Submission #64775145


Source Code Expand

#include <bits/stdc++.h>
 
using namespace std;

const int MOD=1e9+7;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	
	vector<vector<int>> gr(n+1);
	for(int i=0; i<m; i++) {
		int x,y;
		cin>>x>>y;
		gr[x].push_back(y);
		gr[y].push_back(x);
	}
	
	vector<int> cca(n+1);
	vector<set<int>> ccs(n+1);
	
	for(int i=1; i<=n; i++){
		cca[i]=i;
		ccs[i].insert(i);
	}
	
	auto merge =[&](int x, int y){
		if(cca[x]==cca[y]) return; 
		
		if(ccs[cca[x]].size()<ccs[cca[y]].size()){
			swap(x,y);
		}
		
		int oldy=cca[y];
		for(int z:ccs[oldy]){
			cca[z]=cca[x];
			ccs[cca[x]].insert(z);
		}
		
		
	};
	set<int> big;
	
	
	for(int i=1; i<=n; i++){
		for(int x:gr[i]){
			if(x<i){
				merge(x,i);
				
			}
			else{
				big.insert(x);
				
			}
			
		}
		while(big.size()){
			auto it=big.begin();
			if(*it<=i) big.erase(it);
			else break; 
		}
		cout<<(ccs[cca[1]].size()==i?(int)big.size():-1)<<'\n'; 
		
	}
	
	
	
	
    return 0;
}

Submission Info

Submission Time
Task E - Reachable Set
User usernameson
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1042 Byte
Status AC
Exec Time 316 ms
Memory 50336 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:66:42: warning: comparison of integer expressions of different signedness: ‘std::set<int>::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
   66 |                 cout<<(ccs[cca[1]].size()==i?(int)big.size():-1)<<'\n';
      |                        ~~~~~~~~~~~~~~~~~~^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 4
AC × 49
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3564 KiB
00_sample_01.txt AC 1 ms 3472 KiB
00_sample_02.txt AC 1 ms 3560 KiB
00_sample_03.txt AC 1 ms 3428 KiB
01_random_04.txt AC 127 ms 43044 KiB
01_random_05.txt AC 186 ms 43688 KiB
01_random_06.txt AC 155 ms 43048 KiB
01_random_07.txt AC 146 ms 44004 KiB
01_random_08.txt AC 316 ms 49960 KiB
01_random_09.txt AC 265 ms 47960 KiB
01_random_10.txt AC 300 ms 49012 KiB
01_random_11.txt AC 287 ms 45096 KiB
01_random_12.txt AC 300 ms 47796 KiB
01_random_13.txt AC 290 ms 47796 KiB
01_random_14.txt AC 315 ms 47700 KiB
01_random_15.txt AC 51 ms 7808 KiB
01_random_16.txt AC 40 ms 17616 KiB
01_random_17.txt AC 20 ms 25208 KiB
01_random_18.txt AC 4 ms 6468 KiB
01_random_19.txt AC 4 ms 6700 KiB
01_random_20.txt AC 23 ms 5980 KiB
01_random_21.txt AC 15 ms 4144 KiB
01_random_22.txt AC 4 ms 3812 KiB
01_random_23.txt AC 30 ms 7228 KiB
01_random_24.txt AC 29 ms 6128 KiB
01_random_25.txt AC 17 ms 4816 KiB
01_random_26.txt AC 266 ms 50336 KiB
01_random_27.txt AC 212 ms 47148 KiB
01_random_28.txt AC 197 ms 43996 KiB
01_random_29.txt AC 220 ms 46392 KiB
01_random_30.txt AC 266 ms 50312 KiB
01_random_31.txt AC 223 ms 47196 KiB
01_random_32.txt AC 202 ms 43928 KiB
01_random_33.txt AC 211 ms 46404 KiB
01_random_34.txt AC 256 ms 50284 KiB
01_random_35.txt AC 210 ms 47212 KiB
01_random_36.txt AC 197 ms 44028 KiB
01_random_37.txt AC 210 ms 46400 KiB
01_random_38.txt AC 1 ms 3472 KiB
01_random_39.txt AC 1 ms 3500 KiB
01_random_40.txt AC 1 ms 3480 KiB
01_random_41.txt AC 1 ms 3428 KiB
01_random_42.txt AC 1 ms 3480 KiB
01_random_43.txt AC 1 ms 3496 KiB
01_random_44.txt AC 1 ms 3488 KiB
01_random_45.txt AC 1 ms 3428 KiB
01_random_46.txt AC 1 ms 3440 KiB
01_random_47.txt AC 1 ms 3500 KiB
01_random_48.txt AC 1 ms 3472 KiB