Advertisement
smatskevich

Lesson17

Mar 25th, 2023
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.   int n = 0; cin >> n;
  8.   int m = 0; cin >> m;
  9.   vector<vector<int>> out_edges(n);
  10.   for (int i = 0; i < m; ++i) {
  11.     int a, b; cin >> a >> b;
  12.     out_edges[a].push_back(b);
  13.   }
  14.  
  15.   vector<vector<int>> in_edges(n);
  16.   for (int u = 0; u < n; ++u) {
  17.     // for (int k = 0; k < out_edges[i].size(); ++k) {
  18.     //   int j = out_edges[i][k];
  19.     // for (auto k = out_edges[i].begin(); k != out_edges[i].end(); ++k) {
  20.     //   int j = *k;
  21.     for (int v : out_edges[u])
  22.       in_edges[v].push_back(u);
  23.   }
  24.  
  25.   for (int u = 0; u < n; ++u) {
  26.     cout << u << ": ";
  27.     for (int x : in_edges[u]) cout << x << " ";
  28.     cout << endl;
  29.   }
  30.   return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement