Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 200043;
- set<int> g[N];
- set<int> unused;
- int cc = 0;
- vector<int> comps;
- void dfs(int x)
- {
- unused.erase(x);
- comps[cc]++;
- int cur = -1;
- while(true)
- {
- auto it = unused.upper_bound(cur);
- if (it == unused.end())
- break;
- cur = *it;
- if (g[x].count(cur))
- continue;
- dfs(cur);
- }
- }
- int main()
- {
- int n, m;
- cin >> n >> m;
- for(int i = 0; i < m; i++)
- {
- int x, y;
- scanf("%d %d", &x, &y);
- --x;
- --y;
- g[x].insert(y);
- g[y].insert(x);
- }
- for(int i = 0; i < n; i++)
- unused.insert(i);
- for(int i = 0; i < n; i++)
- if (unused.count(i))
- {
- comps.push_back(0);
- dfs(i);
- cc++;
- }
- sort(comps.begin(), comps.end());
- printf("%d\n", cc);
- for(int i = 0; i < cc; i++)
- printf("%d ", comps[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement