QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#670904#906. 强连通分量yhdddAC ✓384ms82576kbC++201.9kb2024-10-24 08:30:582024-10-24 08:30:59

Judging History

你现在查看的是最新测评结果

  • [2024-10-24 08:30:59]
  • 评测
  • 测评结果:AC
  • 用时:384ms
  • 内存:82576kb
  • [2024-10-24 08:30:58]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=500010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,m;
int head[maxn],tot=1;
struct nd{
	int nxt,to;
}e[maxn];
void add(int u,int v){e[++tot]={head[u],v};head[u]=tot;}
int dfn[maxn],lw[maxn],idx;
vector<int> id[maxn];
int scc[maxn],scct;
int st[maxn],tp;
void tar(int u){
	st[++tp]=u,dfn[u]=lw[u]=++idx;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(!dfn[v]){
			tar(v);
			lw[u]=min(lw[u],lw[v]);
		}
		else if(!scc[v])lw[u]=min(lw[u],dfn[v]);
	}
	if(dfn[u]==lw[u]){
		id[++scct].pb(st[tp]),scc[st[tp]]=scct;
		while(st[tp--]!=u)id[scct].pb(st[tp]),scc[st[tp]]=scct;
	}
}
vector<int> g[maxn];
queue<int> q;
int d[maxn];
void work(){
	n=read();m=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read();
		add(u+1,v+1);
	}
	for(int i=1;i<=n;i++)if(!dfn[i])tar(i);
	for(int u=1;u<=n;u++){
		for(int i=head[u];i;i=e[i].nxt){
			int v=e[i].to;
			if(scc[u]!=scc[v])g[scc[u]].pb(scc[v]),d[scc[v]]++;
		}
	}
	for(int i=1;i<=scct;i++)if(!d[i])q.push(i);
	printf("%lld\n",scct);
	while(!q.empty()){
		int u=q.front();q.pop();
		sort(id[u].begin(),id[u].end(),greater<int>());
		printf("%lld ",id[u].size());
		for(int j:id[u])printf("%lld ",j-1);puts("");
		for(int v:g[u]){
			d[v]--;
			if(!d[v])q.push(v);
		}
	}
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7788kb

input:

6 7
1 4
5 2
3 0
5 5
4 1
0 3
4 2

output:

4
2 3 0 
2 4 1 
1 5 
1 2 

result:

ok OK

Test #2:

score: 0
Accepted
time: 284ms
memory: 82576kb

input:

500000 500000
389812 410922
255712 339244
274009 248522
347288 199231
235313 301629
469588 84917
364188 449407
392348 436920
26220 198288
162188 468965
274222 92196
463222 408478
231663 467768
382681 38083
412497 160479
280851 268689
101149 25450
62271 9177
38892 268598
273853 250782
191939 89247
40...

output:

499590
1 3 
1 4 
1 5 
1 6 
1 7 
1 10 
1 13 
1 14 
1 17 
1 19 
1 20 
1 21 
1 24 
1 25 
1 26 
1 27 
1 31 
1 32 
1 34 
1 37 
1 39 
1 42 
1 43 
1 46 
1 47 
1 59 
1 60 
1 67 
1 68 
1 76 
1 80 
1 85 
1 86 
1 88 
1 89 
1 94 
1 107 
1 111 
1 113 
1 114 
1 119 
1 120 
1 121 
1 123 
1 129 
1 130 
1 132 
1 133...

result:

ok OK

Test #3:

score: 0
Accepted
time: 374ms
memory: 82188kb

input:

500000 500000
463045 412906
148756 435111
210547 370466
332006 125085
346657 373200
141009 248049
418869 36311
103205 31879
79919 221632
325039 63377
463225 21697
115522 423754
468924 422567
113104 10277
106927 168428
136657 198931
52292 164110
411164 269182
115111 229801
490548 374967
35584 124385
...

output:

499391
1 1 
1 2 
1 6 
1 12 
1 13 
1 18 
1 19 
1 20 
1 25 
1 26 
1 28 
1 32 
1 36 
1 38 
1 41 
1 47 
1 48 
1 49 
1 51 
1 52 
1 57 
1 60 
1 68 
1 70 
1 71 
1 72 
1 73 
1 74 
1 77 
1 78 
1 79 
1 81 
1 84 
1 86 
1 95 
1 96 
1 98 
1 99 
1 101 
1 102 
1 106 
1 107 
1 110 
1 112 
1 113 
1 121 
1 124 
1 134...

result:

ok OK

Test #4:

score: 0
Accepted
time: 378ms
memory: 82204kb

input:

500000 500000
53335 382346
455173 92221
8244 323792
50176 7825
97274 483122
91479 85438
76999 26861
226585 485061
342260 162826
198446 160509
358060 405334
116619 383398
228241 455075
383689 132273
411544 91882
201903 245543
215635 97032
216514 238391
267192 179008
82221 449619
70697 492859
212515 4...

output:

499543
1 1 
1 2 
1 3 
1 6 
1 7 
1 8 
1 12 
1 13 
1 16 
1 18 
1 19 
1 21 
1 23 
1 26 
1 30 
1 34 
1 35 
1 37 
1 40 
1 42 
1 43 
1 45 
1 56 
1 61 
1 66 
1 67 
1 68 
1 70 
1 74 
1 75 
1 81 
1 82 
1 88 
1 89 
1 96 
1 103 
1 104 
1 105 
1 109 
1 110 
1 111 
1 124 
1 125 
1 131 
1 132 
1 133 
1 135 
1 136...

result:

ok OK

Test #5:

score: 0
Accepted
time: 384ms
memory: 82188kb

input:

500000 500000
429248 25838
130385 474090
301066 98435
160342 325081
58836 93676
332873 451375
243336 362476
378833 389318
68972 375267
209749 483838
405727 431354
477871 331401
30320 382468
228018 369242
53158 111145
464333 346455
436090 431682
22494 69335
128989 418926
392117 10791
347423 40861
389...

output:

499908
1 1 
1 5 
1 9 
1 10 
1 12 
1 14 
1 15 
1 17 
1 19 
1 21 
1 24 
1 29 
1 32 
1 33 
1 34 
1 35 
1 36 
1 37 
1 38 
1 42 
1 43 
1 49 
1 50 
1 54 
1 56 
1 61 
1 63 
1 64 
1 68 
1 70 
1 71 
1 73 
1 78 
1 82 
1 84 
1 86 
1 87 
1 88 
1 91 
1 92 
1 93 
1 94 
1 96 
1 97 
1 101 
1 105 
1 108 
1 110 
1 11...

result:

ok OK

Test #6:

score: 0
Accepted
time: 366ms
memory: 82212kb

input:

500000 500000
277011 99116
287358 208082
234935 137730
116691 98476
82482 189249
370363 155677
444563 130877
78567 341204
189970 68991
431098 85511
440553 434235
156042 397537
261550 375332
9361 490701
94399 397514
462108 395197
236023 224717
77596 260090
171065 59494
72281 195466
37329 322314
13123...

output:

499959
1 0 
1 1 
1 3 
1 9 
1 11 
1 13 
1 15 
1 16 
1 17 
1 18 
1 19 
1 22 
1 28 
1 29 
1 31 
1 34 
1 35 
1 36 
1 38 
1 39 
1 40 
1 45 
1 46 
1 50 
1 57 
1 58 
1 59 
1 60 
1 61 
1 64 
1 68 
1 69 
1 70 
1 71 
1 75 
1 76 
1 79 
1 83 
1 85 
1 90 
1 93 
1 95 
1 98 
1 101 
1 103 
1 105 
1 106 
1 110 
1 11...

result:

ok OK

Test #7:

score: 0
Accepted
time: 256ms
memory: 68056kb

input:

389813 410923
255712 339244
274009 248522
347288 199231
235313 301629
84917 364188
26220 198288
162188 274222
92196 231663
382681 38083
160479 280851
268689 101149
25450 62271
9177 38892
268598 273853
250782 191939
89247 384002
197410 212876
258774 238988
55975 128576
220526 321996
203733 68224
2156...

output:

386899
1 0 
1 2 
1 5 
1 7 
1 12 
1 14 
1 19 
1 20 
1 21 
1 24 
1 25 
1 26 
1 28 
1 31 
1 32 
1 33 
1 34 
1 37 
1 38 
1 39 
1 42 
1 47 
1 48 
1 49 
1 51 
1 55 
1 59 
1 71 
1 82 
1 85 
1 88 
1 89 
1 90 
1 96 
1 98 
1 105 
1 106 
1 107 
1 111 
1 113 
1 114 
1 115 
1 120 
1 128 
1 129 
1 131 
1 133 
1 1...

result:

ok OK

Test #8:

score: 0
Accepted
time: 288ms
memory: 75388kb

input:

463046 412907
148756 435111
210547 370466
332006 125085
346657 373200
141009 248049
418869 36311
103205 31879
79919 221632
325039 63377
21697 115522
423754 422567
113104 10277
106927 168428
136657 198931
52292 164110
411164 269182
115111 229801
374967 35584
124385 307573
453747 96444
292667 195578
1...

output:

463024
1 2 
1 6 
1 11 
1 12 
1 13 
1 17 
1 18 
1 24 
1 25 
1 26 
1 29 
1 32 
1 38 
1 41 
1 43 
1 44 
1 47 
1 49 
1 51 
1 52 
1 55 
1 57 
1 60 
1 63 
1 68 
1 70 
1 71 
1 75 
1 76 
1 78 
1 81 
1 82 
1 84 
1 85 
1 86 
1 89 
1 92 
1 93 
1 94 
1 96 
1 99 
1 101 
1 106 
1 107 
1 110 
1 113 
1 114 
1 116 
...

result:

ok OK

Test #9:

score: 0
Accepted
time: 36ms
memory: 22048kb

input:

53336 382347
26685 8244
50176 7825
31738 24370
25943 19902
11463 26861
29977 26309
14580 31754
1838 29437
30380 12118
51083 31633
1201 18328
26346 5295
48935 19027
31496 19906
41783 5048
47936 16685
5161 34107
15907 28002
332 27672
28930 39563
36429 31696
17876 726
42526 21682
35319 8727
17974 25252...

output:

87
1 1694 
1 2827 
1 4368 
1 4989 
1 5924 
1 7456 
1 7881 
1 10979 
1 11778 
1 12568 
1 18187 
1 20997 
1 23200 
1 24291 
1 24488 
1 25764 
1 27701 
1 27910 
1 28249 
1 28488 
1 29555 
1 30131 
1 30693 
1 31150 
1 32654 
1 35935 
1 38700 
1 41786 
1 48041 
1 49039 
1 49069 
1 49292 
1 49821 
1 51147...

result:

ok OK

Test #10:

score: 0
Accepted
time: 60ms
memory: 60632kb

input:

429249 25839
130385 301066
98435 160342
325081 58836
93676 332873
243336 362476
378833 389318
68972 375267
209749 405727
331401 30320
382468 228018
369242 53158
111145 346455
22494 69335
128989 418926
392117 10791
347423 40861
389364 17417
261217 42171
167706 71369
107485 278424
39639 144680
60220 1...

output:

429249
1 0 
1 1 
1 2 
1 3 
1 4 
1 5 
1 6 
1 7 
1 9 
1 10 
1 11 
1 12 
1 13 
1 14 
1 15 
1 16 
1 17 
1 18 
1 19 
1 20 
1 21 
1 22 
1 23 
1 24 
1 25 
1 26 
1 27 
1 28 
1 29 
1 30 
1 31 
1 32 
1 33 
1 34 
1 35 
1 36 
1 38 
1 39 
1 40 
1 41 
1 42 
1 43 
1 44 
1 45 
1 46 
1 47 
1 48 
1 50 
1 52 
1 53 
1 ...

result:

ok OK

Test #11:

score: 0
Accepted
time: 104ms
memory: 47396kb

input:

277012 99117
208082 234935
137730 116691
98476 82482
189249 155677
130877 78567
189970 68991
85511 156042
261550 9361
94399 236023
224717 77596
260090 171065
59494 72281
195466 37329
131235 97595
186133 259682
77924 208661
225412 201669
250472 163723
144340 159695
17876 71198
230537 223132
49533 606...

output:

277012
1 0 
1 1 
1 2 
1 3 
1 4 
1 5 
1 8 
1 11 
1 12 
1 13 
1 14 
1 15 
1 16 
1 17 
1 18 
1 21 
1 22 
1 23 
1 24 
1 25 
1 26 
1 29 
1 31 
1 32 
1 33 
1 34 
1 35 
1 37 
1 38 
1 39 
1 40 
1 41 
1 43 
1 44 
1 45 
1 46 
1 47 
1 48 
1 49 
1 50 
1 52 
1 53 
1 54 
1 55 
1 57 
1 58 
1 60 
1 61 
1 62 
1 63 
...

result:

ok OK