Josif_tepe

Untitled

Jan 28th, 2026
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4.  
  5. using namespace std;
  6. typedef long long ll;
  7. const int maxn = 105;
  8.  
  9. vector<int> graph[maxn];
  10. int main() {
  11.     int n; // number of nodes(vertices)
  12.     cin >> n;
  13.    
  14.     int m; // number of edges
  15.     cin >> m;
  16.    
  17.     for(int i = 0; i < m; i++) {
  18.         int a, b;
  19.         cin >> a >> b;
  20.        
  21.         graph[a].push_back(b);
  22.         graph[b].push_back(a);
  23.     }
  24.    
  25.     vector<int> v = graph[0];
  26.     vector<int> v1 = graph[1];
  27.    
  28.     for(int i = 0; i < n; i++) {
  29.         cout << i << ": ";
  30.         for(int j = 0; j < graph[i].size(); j++) {
  31.             cout << graph[i][j] << " ";
  32.         }
  33.         cout << endl;
  34.     }
  35.    
  36.    
  37.    
  38.    
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment