Advertisement
hung_mine

ONEGCD

Oct 13th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. /// from HUNG MINE with love <3
  4. int n, m, d[100001], k = 1;
  5. vector <int> a[100001];
  6. void bfs () {
  7.       queue <int> q;
  8.       q.push (1);
  9.       while (q.size ()) {
  10.             int u = q.front ();
  11.             q.pop ();
  12.             for (auto v : a[u]) {
  13.                   if (d[v] > 0) {
  14.                         -- d[v];
  15.                         -- d[u];
  16.                         cout << u << " " << v << " " << k << "\n";
  17.                         ++ k;
  18.                         q.push (v);
  19.                   }
  20.             }
  21.       }
  22. }
  23. int main () {
  24.       if (fopen ("test.inp", "r")) {
  25.             freopen ("test.inp", "r", stdin);
  26.       }
  27. //      else {
  28. //            freopen ("ONEGCD.inp", "r", stdin);
  29. //            freopen ("ONEGCD.out", "w", stdout);
  30. //      }
  31.  
  32.       ios_base :: sync_with_stdio (0);
  33.       cin.tie (0);
  34.       cout.tie (0);
  35.       cin >> n >> m;
  36.       for (int i = 1; i <= m; ++ i) {
  37.             int x, y;
  38.             cin >> x >> y;
  39.             a[x].push_back (y);
  40.             a[y].push_back (x);
  41.             ++ d[x];
  42.             ++ d[y];
  43.       }
  44.       for (int i = 1; i <= n; ++ i) {
  45.             sort (a[i].begin (), a[i].end ());
  46.       }
  47.       bfs ();
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement