QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#134942#6634. Central SubsetPlentyOfPenalty#TL 219ms9832kbC++201.5kb2023-08-05 10:12:332023-08-05 10:12:35

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 10:12:35]
  • 评测
  • 测评结果:TL
  • 用时:219ms
  • 内存:9832kb
  • [2023-08-05 10:12:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5;
struct edge{
	int t,nxt;
}e[(N<<1)+10];
int T,n,D,m,u,v,f[N+10],be[N+10],cnt;
int fa[N+10],dep[N+10],mk[N+10],mx,mnd[N+10],prt[N+10],sz;
char c;
int getf(int x){
	return f[x]==x?x:f[x]=getf(f[x]);
}
void scan(int&x){
	x=0;
	while(!isdigit(c=getchar()));
	while(isdigit(c))x=(x<<3)+(x<<1)+c-'0',c=getchar();
}
void add(int x,int y){
	e[++cnt]=(edge){y,be[x]},be[x]=cnt;
}
void Getdep(int x,int y){
	fa[x]=y,dep[x]=dep[y]+1;
	for(int i=be[x];i;i=e[i].nxt)if(e[i].t!=y)Getdep(e[i].t,x);
}
void Calc(int x){
	if(mk[x]){
		mnd[x]=0;
		return;
	}else mnd[x]=D+1;
	for(int i=be[x];i;i=e[i].nxt)if(e[i].t!=fa[x])Calc(e[i].t),mnd[x]=min(mnd[x],mnd[e[i].t]+1);
}
void Getmx(int x,int mn){
	if(mk[x])return;
	if(mn>D&&mnd[x]>D&&dep[x]>mx)mx=dep[x],u=x;
	for(int i=be[x];i;i=e[i].nxt)if(e[i].t!=fa[x])Getmx(e[i].t,min(mn,mnd[x])+1);
}
int main(){
	scan(T);
	while(T--){
		scanf("%d%d",&n,&m),D=0;
		while(D*D<n)++D;
		for(int i=1;i<=n;++i)f[i]=i,be[i]=mk[i]=0;
		cnt=sz=0;
		for(int i=1;i<=m;++i){
			scan(u),scan(v);
			if(getf(u)!=getf(v))add(u,v),add(v,u),f[f[u]]=f[v];
		}
		Getdep(1,0);
		while(Calc(1),mx=0,Getmx(1,D+1),mx&&sz<=D){
			for(int i=1;i<=D&&fa[u];++i)u=fa[u];
			prt[++sz]=u,mk[u]=1;
		}
		assert(sz<=D);
		printf("%d\n",sz);
		for(int i=1;i<=sz;++i)printf("%d%c",prt[i]," \n"[i==sz]);
	}
	return 0;
}
/*
2
4 3
1 2
2 3
3 4

11 10
1 2
2 3
3 4 
4 5
5 6
1 7
7 8 
8 9
9 10
10 11
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9748kb

input:

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

output:

1
2
1
1

result:

ok correct (2 test cases)

Test #2:

score: 0
Accepted
time: 13ms
memory: 9816kb

input:

10000
15 14
13 12
5 4
9 8
11 12
15 14
10 9
14 13
2 3
2 1
6 5
10 11
3 4
7 6
8 7
6 5
2 1
2 4
4 6
2 3
3 5
10 9
8 3
9 4
5 6
5 10
3 2
5 4
2 7
1 2
4 3
2 1
2 1
2 1
2 1
9 8
9 8
5 4
1 2
6 5
3 4
3 2
7 8
7 6
2 1
1 2
14 13
3 10
5 6
2 9
11 4
2 3
2 1
8 7
13 6
5 4
5 12
6 7
4 3
7 14
16 15
2 3
2 1
6 10
6 9
6 4
9 11
...

output:

2
11 2
1
1
1
2
1
1
1
1
2
6 1
1
1
1
4
2
10 1
1
1
2
15 4
1
3
1
2
1
5
1
1
2
11 2
1
1
1
1
1
2
1
1
1
2
1
3
1
4
1
5
1
1
2
11 2
1
1
1
5
1
1
1
1
2
16 5
1
2
1
4
2
7 1
1
1
1
3
1
2
1
3
2
6 7
1
1
2
8 1
1
1
1
3
1
2
1
1
2
6 1
1
3
1
3
1
5
1
1
2
13 2
1
1
1
3
1
4
1
1
2
12 3
1
2
1
2
1
1
1
1
1
2
1
2
1
2
1
2
1
1
2
5 1
...

result:

ok correct (10000 test cases)

Test #3:

score: 0
Accepted
time: 42ms
memory: 7864kb

input:

100
2000 1999
529 528
885 884
1221 1222
375 374
245 244
758 757
711 710
1521 1522
1875 1874
749 750
823 822
1959 1958
1767 1766
155 154
631 632
825 824
1330 1331
457 456
1344 1343
1817 1818
413 414
582 583
1828 1827
1335 1336
654 655
162 161
1668 1667
1966 1967
1472 1471
1185 1184
518 517
1509 1510
...

output:

22
1955 1864 1773 1682 1591 1500 1409 1318 1227 1136 1045 954 863 772 681 590 499 408 317 226 135 44
1
1
12
956 867 778 689 600 511 422 333 244 155 66 1
4
1170 1047 107 32
1
1
22
1955 1864 1773 1682 1591 1500 1409 1318 1227 1136 1045 954 863 772 681 590 499 408 317 226 135 44
1
1
12
956 867 778 689 ...

result:

ok correct (100 test cases)

Test #4:

score: 0
Accepted
time: 219ms
memory: 9372kb

input:

10
14914 14913
13959 13958
3643 3642
4582 4581
13378 13379
981 980
12901 12902
12355 12356
14692 14691
9670 9669
14632 14631
1441 1440
1367 1368
6237 6238
8297 8298
1021 1020
5096 5097
4773 4774
7778 7779
3013 3014
5536 5535
11621 11620
13904 13903
3050 3049
14179 14178
7471 7472
13380 13381
7403 74...

output:

61
14791 14544 14297 14050 13803 13556 13309 13062 12815 12568 12321 12074 11827 11580 11333 11086 10839 10592 10345 10098 9851 9604 9357 9110 8863 8616 8369 8122 7875 7628 7381 7134 6887 6640 6393 6146 5899 5652 5405 5158 4911 4664 4417 4170 3923 3676 3429 3182 2935 2688 2441 2194 1947 1700 1453 12...

result:

ok correct (10 test cases)

Test #5:

score: 0
Accepted
time: 37ms
memory: 9832kb

input:

10
20000 19999
6831 6760
15763 15900
10362 10184
5821 5880
17555 17389
16708 16574
11592 11436
186 209
19380 19313
8867 8718
12100 12237
16245 16110
18464 18568
4713 4665
17412 17578
18666 18750
4360 4322
12350 12502
4054 4103
2874 2849
8097 8202
14489 14639
1056 1016
13500 13581
2435 2391
199 173
8...

output:

2
6126 1143
4
10809 8283 176 142
3
11257 8040 471
3
10584 9863 2437
5
15169 14623 6490 5958 1
4
15046 6159 4075 1
4
15985 6581 972 256
4
7843 6192 5415 266
4
14312 1588 1025 27
4
8901 8799 7775 387

result:

ok correct (10 test cases)

Test #6:

score: -100
Time Limit Exceeded

input:

1
200000 199999
136649 136648
44943 44944
7148 7149
50332 50333
149967 149966
28976 28975
78549 78550
178698 178697
96434 96433
7859 7858
88976 88977
23348 23347
161682 161681
125393 125392
67892 67893
73592 73593
179054 179055
110841 110842
163714 163715
7982 7981
56309 56310
196486 196485
19176 19...

output:


result: