Advertisement
Josif_tepe

Untitled

Dec 16th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4. using namespace std;
  5. const int maxn = 1e5 + 10;
  6.  
  7. vector<int> graph[maxn];
  8. int main()
  9. {
  10.     int num_of_vertices;
  11.     cin >> num_of_vertices;
  12.    
  13.     int num_of_edges;
  14.     cin >> num_of_edges;
  15.    
  16.     for(int i = 0; i < num_of_edges; i++) {
  17.         int a, b;
  18.         cin >> a >> b;
  19.        
  20.         graph[a].push_back(b);
  21.         graph[b].push_back(a);
  22.     }
  23.    
  24.     for(int i = 0; i < num_of_vertices; i++) {
  25.         for(int j = 0; j < (int) graph[i].size(); j++) {
  26.             cout << i << " --> " << graph[i][j] << endl;
  27.         }
  28.     }
  29.    
  30.  
  31.    
  32.     return 0;
  33.  
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement