Advertisement
Josif_tepe

Untitled

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