Facebook
From Scorching Cheetah, 4 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 23
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. void addEdge(vector<int> adj[], int x, int y)
  8. {
  9.     if (x != y)
  10.     {
  11.         adj[x].push_back(y);
  12.     }  
  13.     adj[y].push_back(x);
  14. }
  15.  
  16. void printGraph(vector<int> adj[], int V)
  17. {
  18.     cout << "lista: \n";
  19.     for (int v = 0; v < V; ++v)
  20.     {
  21.         cout << v+1 << ":";
  22.         for (auto x : adj[v])
  23.            cout << " " << x+1;
  24.         printf("\n");
  25.     }
  26. }
  27.  
  28.  
  29. int main()
  30. {
  31.     int n, m; cin >> n >> m;
  32.     vector<int> adj[n];
  33.     int tablicaaa[n][n] = {0};
  34.     int x, y;
  35.     for (int i = 0; i < m; i++)
  36.     {
  37.         cin >> x >> y;
  38.         addEdge(adj, x-1, y-1);
  39.         tablicaaa[x-1][y-1] = 1;
  40.         tablicaaa[y-1][x-1] = 1;
  41.     }
  42.     printGraph(adj, n);
  43.     return 0;
  44. }
  45.  
  46. // 5 7 0 1 0 4 1 2 1 3 1 4 2 3 3 4
  47. //7 12 1 2 1 4 2 3 3 4 3 2 4 5 4 6 4 7 7 7 5 6 5 7 6 7