Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int n = 0; cin >> n;
- int m = 0; cin >> m;
- vector<vector<int>> out_edges(n);
- for (int i = 0; i < m; ++i) {
- int a, b; cin >> a >> b;
- out_edges[a].push_back(b);
- }
- vector<vector<int>> in_edges(n);
- for (int u = 0; u < n; ++u) {
- // for (int k = 0; k < out_edges[i].size(); ++k) {
- // int j = out_edges[i][k];
- // for (auto k = out_edges[i].begin(); k != out_edges[i].end(); ++k) {
- // int j = *k;
- for (int v : out_edges[u])
- in_edges[v].push_back(u);
- }
- for (int u = 0; u < n; ++u) {
- cout << u << ": ";
- for (int x : in_edges[u]) cout << x << " ";
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement