Advertisement
Josif_tepe

Untitled

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