Advertisement
matheus_monteiro

Coleção de Upas

Sep 18th, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MAX = 200000; //2 * 10^5
  5.  
  6. vector<int> G[MAX];
  7. bool cor[MAX];
  8. int n, m;
  9.  
  10. int32_t main() {
  11.     cin >> n >> m;
  12.     while(m--) {
  13.         int u, v;
  14.         cin >> u >> v;
  15.         G[u].push_back(v);
  16.         G[v].push_back(u);
  17.     }
  18.     vector<int> ans;
  19.     for(int i = n; i >= 1; i--) {
  20.         bool fl = false;
  21.         for(int &v : G[i])
  22.             fl |= cor[v];
  23.         if(!fl) {
  24.             ans.push_back(i);
  25.             cor[i] = 1;
  26.         }
  27.     }
  28.  
  29.     cout << ans.size() << '\n';
  30.     for(int i = (int)ans.size() - 1; i >= 0; i--)
  31.         cout << ans[i] << ' ';
  32.     puts("");
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement