QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#557384#8220. 众生之门zhanghuanrui5 148ms6108kbC++142.5kb2024-09-11 09:23:292024-09-11 09:23:29

Judging History

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

  • [2024-09-11 09:23:29]
  • 评测
  • 测评结果:5
  • 用时:148ms
  • 内存:6108kb
  • [2024-09-11 09:23:29]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef zhr_debug
#define debug printf
#endif
#ifndef zhr_debug
void debug(const char* s,...){}
#endif
using namespace std;
inline int randrange(int l,int r){return (rand()<<15|rand())%(r-l+1)+l;}
void freopen(string file){freopen((file+".in").c_str(),"r",stdin);freopen((file+".out").c_str(),"w",stdout);}
int n,s,t;
vector<int> e[50020];
int dep[50020];
int sz[50020];
int son[50020];
int top[50020];
int fa[50020];
void dfs1(int x,int f)
{
	fa[x]=f;
	sz[x]=1;
	dep[x]=dep[f]+1;
	for(int v:e[x])
	{
		if(v==f) continue;
		dfs1(v,x);
		sz[x]+=sz[v];
		if(sz[v]>sz[son[x]]) son[x]=v;
	}
}
void dfs2(int x,int f,int tp)
{
	top[x]=tp;
	if(son[x]) dfs2(son[x],x,tp);
	for(int v:e[x])
	{
		if(v==f || v==son[x]) continue;
		dfs2(v,x,v);
	}
}
int getlca(int x,int y)
{
	while(top[x]^top[y])
	{
		if(dep[top[x]]<dep[top[y]]) swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y] ? x : y;
}
inline int getdis(int x,int y){return dep[x]+dep[y]-2*dep[getlca(x,y)];}
void initialize()
{
	for(int i=1;i<=n;i++) e[i].clear();
	fill(son,son+n+1,0);
}
int a[50020];
namespace __Sub1
{
	int dis[15][15];
	int ans[50020];
	int mn,cur;
	void solve()
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				dis[i][j]=getdis(i,j);
			}
		}
		mn=0x3f3f3f3f;
		do
		{
			cur=0;
			for(int i=1;i<n;i++) cur^=dis[a[i]][a[i+1]];
			if(cur<mn)
			{
				mn=cur;
				for(int i=1;i<=n;i++) ans[i]=a[i];
			}
		}
		while(next_permutation(a+2,a+n));
		for(int i=1;i<=n;i++) printf("%d ",ans[i]);printf("\n");
	}
}
bool flower()
{
	for(int i=1;i<=n;i++) if(e[i].size()==n-1) return true;
	return false;
}
int calc(int x)
{
	return getdis(a[x-1],a[x])^getdis(a[x],a[x+1]);
}
void solve()
{
	cin>>n>>s>>t;
	initialize();
	for(int i=1,x,y;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	dfs1(1,0);
	dfs2(1,0,1);
	a[1]=s;a[n]=t;
	for(int i=1,p=1;i<=n;i++)
	{
		if(i==s || i==t) continue;
		a[++p]=i;
	}
	if(n<=9)
	{
		__Sub1::solve();
		return;
	}
	if(flower())
	{
		for(int i=1;i<=n;i++) printf("%d ",a[i]);printf("\n");
		return;
	}
	int cur=0;
	for(int i=1;i<n;i++) cur^=getdis(a[i],a[i+1]);
	while(cur>1)
	{
		int x=randrange(2,n-1),y=randrange(2,n-1);
		while(x==y) y=randrange(2,n-1);
		cur^=calc(x)^calc(y);
		swap(a[x],a[y]);
		cur^=calc(x)^calc(y);
	}
	for(int i=1;i<=n;i++) printf("%d ",a[i]);printf("\n");
}
int main()
{
	srand(time(0));
	int t;
	cin>>t;
	while(t--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 1ms
memory: 5068kb

input:

114
6 5 6
2 6
1 6
4 5
3 1
6 4
6 3 6
2 4
4 1
6 4
1 5
5 3
6 6 1
5 2
1 2
4 6
2 4
3 2
6 6 1
3 6
5 3
1 6
4 2
2 5
6 3 1
5 3
2 4
1 5
4 3
6 3
4 3 4
2 3
1 4
4 3
6 3 1
2 3
6 3
4 3
1 6
5 1
5 3 2
1 2
4 2
2 3
5 2
6 1 4
2 1
5 2
4 1
6 2
3 6
6 5 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 7 5 ...

result:

ok Answer correct!

Test #3:

score: 5
Accepted
time: 2ms
memory: 6036kb

input:

136
8 2 1
3 4
6 1
1 8
7 8
4 8
5 8
8 2
7 5 4
2 4
4 5
3 6
7 5
6 1
1 5
8 7 1
5 6
6 8
8 7
2 3
4 3
1 8
3 1
6 2 3
1 5
5 3
6 5
4 5
3 2
7 5 3
6 1
1 4
4 7
2 3
3 6
7 5
8 7 2
2 3
6 2
1 7
4 1
5 4
8 4
3 8
8 7 3
6 7
5 4
4 7
8 1
3 8
1 5
2 7
7 5 2
3 4
7 3
6 4
1 5
2 5
4 2
7 2 3
3 5
1 5
5 2
7 2
4 2
6 1
8 3 7
2 8
7 8
...

output:

2 3 4 5 6 7 8 1 
5 1 2 6 3 7 4 
7 2 3 4 5 6 8 1 
2 5 1 4 6 3 
5 1 2 4 6 7 3 
7 1 3 4 5 8 6 2 
7 1 2 4 8 5 6 3 
5 1 4 3 6 7 2 
2 1 4 7 5 6 3 
3 1 2 4 5 8 6 7 
3 1 4 6 7 5 8 2 
4 2 3 5 7 8 6 1 
1 2 5 6 4 3 
8 1 2 3 7 6 5 4 
6 2 3 4 5 7 1 
6 2 3 4 5 7 1 
5 1 2 4 8 7 6 3 
1 2 3 4 5 6 
1 2 4 5 3 
2 1 3 4...

result:

ok Answer correct!

Test #4:

score: 5
Accepted
time: 2ms
memory: 5128kb

input:

204
7 6 7
1 6
2 5
7 1
2 3
5 1
4 6
2 2 1
1 2
2 1 2
2 1
4 3 4
1 2
2 3
2 4
2 2 1
2 1
3 2 1
3 1
1 2
8 4 3
5 2
5 4
1 3
8 7
1 5
6 8
5 7
3 2 3
2 3
2 1
6 3 5
1 6
4 5
1 2
3 2
2 5
8 2 1
7 6
3 5
8 6
8 4
3 4
7 2
1 3
7 5 6
3 7
4 1
6 2
5 3
7 1
7 6
3 2 1
3 1
1 2
8 3 2
4 3
2 5
2 4
1 8
1 6
1 2
5 7
4 1 2
4 3
4 2
1 4
...

output:

6 1 2 3 5 4 7 
2 1 
1 2 
3 1 2 4 
2 1 
2 3 1 
4 1 2 5 6 8 7 3 
2 1 3 
3 2 6 1 4 5 
2 3 4 5 7 6 8 1 
5 1 2 7 4 3 6 
2 3 1 
3 1 4 6 7 8 5 2 
1 3 4 2 
2 1 
4 1 5 3 2 7 6 
2 1 4 3 5 
2 1 4 3 
4 1 2 5 7 6 8 3 
6 1 2 3 4 7 5 8 
3 1 2 
6 1 2 3 5 4 
2 1 
6 1 3 4 5 7 2 
2 1 
3 1 2 
2 3 1 
2 1 
5 1 2 4 7 8 6 ...

result:

ok Answer correct!

Test #5:

score: 5
Accepted
time: 0ms
memory: 6108kb

input:

204
6 4 6
5 1
4 1
2 4
5 6
3 5
7 7 1
3 2
2 6
7 5
1 2
3 4
5 4
7 2 1
5 6
7 3
3 2
1 3
5 1
4 5
8 3 7
5 8
1 2
8 7
8 1
5 3
6 8
5 4
8 6 1
2 4
6 3
7 4
4 6
8 1
1 7
6 5
3 3 2
3 2
1 2
8 8 5
5 8
2 3
2 6
4 3
7 2
3 1
8 3
4 4 3
4 3
2 1
3 2
8 6 1
3 4
4 7
4 6
8 2
8 1
6 1
6 5
7 4 7
3 1
4 6
5 2
6 7
2 4
1 4
7 2 1
1 7
4 ...

output:

4 1 5 3 2 6 
7 2 3 6 4 5 1 
2 3 4 6 5 7 1 
3 1 2 5 4 8 6 7 
6 2 3 4 5 7 8 1 
3 1 2 
8 1 2 3 6 7 4 5 
4 2 1 3 
6 2 3 4 5 8 7 1 
4 1 3 2 5 6 7 
2 3 4 5 6 7 1 
1 3 2 
8 1 2 3 5 6 4 7 
1 3 2 
3 2 4 5 1 
2 3 1 
5 1 2 6 7 4 3 
2 1 
2 3 1 4 5 
3 1 4 5 2 6 
4 1 2 3 6 5 7 8 
2 3 1 
2 1 3 
7 1 3 4 5 8 6 2 
3 ...

result:

ok Answer correct!

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #6:

score: 0
Wrong Answer
time: 1ms
memory: 5324kb

input:

87
12 3 7
8 6
12 11
9 10
2 9
5 6
4 9
7 3
11 4
10 7
6 11
1 6
12 5 8
12 9
8 5
7 5
9 5
4 9
10 9
6 8
2 7
11 2
1 2
3 5
12 7 4
8 10
4 6
2 6
9 7
12 9
11 5
1 7
6 12
5 12
3 11
10 2
12 2 5
11 12
10 7
1 9
8 3
7 1
6 9
12 9
4 6
5 7
9 2
3 12
12 10 7
6 4
4 9
5 11
9 10
11 4
1 4
7 4
2 11
12 9
8 10
3 4
12 12 2
8 1
7 ...

output:

3 1 2 4 5 6 8 9 10 11 12 7 
7 0 0 3 4 0 0 11 2 9 12 8 
7 1 2 3 5 10 8 9 6 11 12 4 
1 9 4 12 6 7 8 10 10 11 0 5 
10 0 2 3 4 5 6 8 9 11 12 7 
12 2 3 4 5 6 7 3 9 10 11 2 
5 1 2 8 4 6 9 3 7 11 10 
7 1 3 4 5 6 2 8 9 11 12 10 
0 4 2 5 1 6 1 8 0 10 5 
5 1 2 3 6 7 8 9 10 11 12 4 
8 1 3 4 5 6 7 9 10 11 2 
11...

result:

FAIL Your path should begin with s in test case 2.

Subtask #3:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 120ms
memory: 5124kb

input:

14190
43 27 2
42 3
30 36
11 24
21 22
13 8
22 30
31 29
35 1
10 6
2 23
28 17
2 26
7 37
5 19
38 43
33 39
4 28
33 7
25 31
15 1
32 18
34 27
35 12
19 32
20 17
37 42
26 34
39 10
12 27
24 43
18 6
16 9
38 9
14 15
14 41
25 3
40 13
16 8
36 41
20 5
21 40
11 29
41 24 38
21 6
20 14
26 1
6 7
17 16
39 36
8 18
36 11...

output:

0 0 0 13 11 0 7 15 24 0 18 29 1 0 4 40 0 0 0 16 22 0 0 35 0 0 0 34 41 0 0 0 20 36 0 0 0 39 31 28 33 0 2 
24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 25 26 27 28 29 30 31 9 33 34 35 36 37 39 40 41 38 
26 25 2 3 4 6 7 8 9 27 11 17 13 14 15 17 12 16 19 20 21 23 24 25 5 10 22 
1 43 0 ...

result:

wrong answer Integer parameter [name=p[1]] equals to 0, violates the range [1, 43]

Subtask #4:

score: 0
Wrong Answer

Test #18:

score: 0
Wrong Answer
time: 131ms
memory: 5324kb

input:

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

output:

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

result:

wrong answer Integer parameter [name=p[1]] equals to 0, violates the range [1, 13]

Subtask #5:

score: 0
Wrong Answer

Test #25:

score: 0
Wrong Answer
time: 148ms
memory: 5064kb

input:

36059
13 9 4
5 9
10 3
3 1
13 5
12 5
7 4
2 8
8 10
4 9
11 7
6 11
1 4
13 12 6
4 12
13 9
11 2
6 12
9 12
8 5
7 6
5 3
3 7
10 8
1 5
2 10
13 10 8
3 1
5 9
4 8
6 11
7 13
13 5
1 10
12 13
9 4
11 9
2 11
8 10
12 1 4
9 2
2 12
3 2
12 11
8 2
7 4
5 1
4 1
11 7
10 9
6 9
13 10 12
7 5
11 9
12 10
9 8
3 10
8 5
4 13
13 7
6 ...

output:

9 1 2 0 5 6 0 8 10 11 12 13 4 
4 1 12 3 0 0 7 0 9 10 2 0 6 
1 2 7 12 4 5 0 13 9 11 10 5 8 
7 7 0 5 0 11 11 1 13 2 12 4 
11 13 3 3 2 6 10 7 8 9 8 6 12 
12 1 10 3 3 5 7 9 2 11 6 13 8 
1 2 3 4 5 6 7 9 10 11 12 13 8 
8 9 2 4 5 6 7 1 10 3 
11 5 3 8 2 6 7 5 9 10 12 13 1 
4 1 2 3 5 7 8 9 10 11 12 13 6 
9 1...

result:

wrong answer Integer parameter [name=p[4]] equals to 0, violates the range [1, 13]

Subtask #6:

score: 0
Wrong Answer

Test #34:

score: 0
Wrong Answer
time: 3ms
memory: 5360kb

input:

10
1000 165 244
175 661
738 362
280 462
776 922
231 578
963 615
639 836
32 418
519 220
565 733
239 951
768 847
196 200
246 119
591 288
994 586
313 46
971 515
512 811
228 908
627 339
33 337
447 488
616 319
399 727
921 615
421 509
167 354
905 382
20 356
875 414
619 904
824 940
435 244
953 663
719 962
...

output:

165 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 0 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 0 98 99 100 101 10...

result:

wrong answer Integer parameter [name=p[58]] equals to 0, violates the range [1, 1000]

Subtask #7:

score: 0
Skipped

Dependency #2:

0%