General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
244650704 Practice:
Wasif_Shahzad
920E - 14 C++17 (GCC 7-32) Time limit exceeded on test 9 2000 ms 23752 KB 2024-02-03 10:09:15 2024-02-03 10:09:15
→ Source
//My First ever graph problem at Codeforces.
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define le(i, a, b) for(int i = a; i <= b; i++)
#define ls(i, a, b) for(int i = a; i < b; i++)
#define ge(i, a, b) for(int i = a; i >= b; i--)
#define gr(i, a, b) for(int i = a; i > b; i--) 
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define test_cases int t; cin >> t; while(t--)

const int N = 300000;
vector<set<int>> graph;
set<int> vis;
int n, m;
vector<vector<int>> cc;
vector<int> c_cc, c_size;

void dfs(int v){
	vis.erase(v);
	int last = -1;
	c_cc.pb(v);
	while(true){
		auto it = upper_bound(vis.begin(), vis.end(), last);
		if(it == vis.end()) break;
		last = *it;
		if(!graph[v].count(last)){
			dfs(last);
		}
	}
}

int main(){
	io
	cin >> n >> m;
	graph.resize(n + 1);
	ls(i, 0, m){
		int x, y;
		cin >> x >> y;
		graph[x].insert(y);
		graph[y].insert(x);
	}
	le(i, 1, n){
		vis.insert(i);
	}
	while(!vis.empty()){
		c_cc.clear();
		int u = *vis.begin();
		dfs(u);
		cc.pb(c_cc);
	}
	for(auto x: cc){
		c_size.pb(x.size());
	}
	cout << cc.size() << endl;
	sort(c_size.begin(), c_size.end());
	for(auto x: c_size){
		cout << x << " ";
	}
	cout << "\n";
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details