QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#558836#8220. 众生之门zlttcl5 5ms19676kbC++143.4kb2024-09-11 18:48:112024-09-11 18:48:14

Judging History

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

  • [2024-09-11 18:48:14]
  • 评测
  • 测评结果:5
  • 用时:5ms
  • 内存:19676kb
  • [2024-09-11 18:48:11]
  • 提交

answer

//#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10, inf = 0x3f3f3f3f;
int n, minn, s, t, now, dep[N], dfn[N], dis[210][210], idx, id[N];
int p[N], p2[N], st[21][N], fa[N];
bool vis[N];
vector<int> vec[N];
inline ll read(){
	ll x = 0, m = 1;
	char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') m = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return x * m;
}
inline void write(ll x){
	if(x < 0){
		putchar('-');
		write(-x);
		return;
	}
	if(x >= 10) write(x / 10);
	putchar(x % 10 + '0');
}
inline int dep_min(int x, int y){
	return dep[x] > dep[y] ? y : x;
}
inline int lca(int u, int v){
	if(u == v) return u;
	u = dfn[u], v = dfn[v];
	if(u > v) swap(u, v);
	++ u;
	int x = __lg(v - u + 1);
	return dep_min(st[x][u], st[x][v - (1 << x) + 1]);
}
inline int get_dis(int u, int v){
	if(!u || !v) return -1;
	return dep[u] + dep[v] - (dep[lca(u, v)] << 1);
}
inline void check(){
	int res = 0;
	for(int i = 1; i < n; ++ i) res ^= dis[p[i]][p[i + 1]];
	if(res < minn){
		minn = res;
		for(int i = 1; i <= n; ++ i) p2[i] = p[i];
	}
}
inline void dfs(int u){
	dfn[u] = ++ idx, id[idx] = u;
	for(int v : vec[u]){
		if(v == fa[u]) continue;
		fa[v] = u, dep[v] = dep[u] + 1;
		dfs(v);
	}
}
inline void dfs2(int dep){
	if(dep == n){
		check();
		return;
	}
	for(int i = 1; i <= n; ++ i){
		if(vis[i]) continue;
		if(dis[i][p[dep - 1]] > 4) continue;
		p[dep] = i, vis[i] = 1;
		dfs2(dep + 1), vis[i] = 0;
	}
}
inline void get_in(){
	n = read(), s = read(), t = read(), idx = now = 0;
	for(int i = 1; i <= n; ++ i) vec[i].clear(), dep[i] = fa[i] = 0;
	for(int i = 2; i <= n; ++ i){
		int u = read(), v = read();
		vec[u].push_back(v), vec[v].push_back(u);
	}
	p[1] = s, p[n] = t;
}
inline void init(){
	dfs(1);
	for(int i = 2; i <= n; ++ i) st[0][i] = fa[id[i]];
	for(int j = 1; j <= 19; ++ j){
		for(int i = 1; i + (1 << j) - 1 <= n; ++ i){
			st[j][i] = dep_min(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
		}
	}
}
inline bool Chrysanthemum(){
	for(int i = 1; i <= n; ++ i) if(vec[i].size() == n - 1) return 1;
	return 0;
}
inline void work(){
	minn = inf;
	for(int i = 1; i <= n; ++ i){
		for(int j = 1; j <= n; ++ j){
			dis[i][j] = get_dis(i, j);
		}
		vis[i] = 0;
	}
	vis[s] = vis[t] = 1;
	dfs2(2);
	for(int i = 1; i <= n; ++ i) write(p2[i]), putchar(' ');
	putchar('\n');
}
inline int get_rand(int l, int r){
	ll x = (1ll * rand() * rand() * rand()) % 1000000000;
	return x % (r - l + 1) + l; 
}
inline int calc(int x){
	return get_dis(p[x - 1], p[x]) ^ get_dis(p[x], p[x + 1]);
}
inline void solve(){
	srand(time(0));
	get_in(), init();	
	for(int i = 1; i <= n; ++ i) if(i != s && i != t) p[i - (i > s) - (i > t) + 1] = i;
	for(int i = 1; i < n; ++ i) now ^= get_dis(p[i], p[i + 1]);
	if(Chrysanthemum()){for(int i = 1; i <= n; ++ i) write(p[i]), putchar(' '); putchar('\n'); return;}
	if(n <= 9){work(); return;}
	while(now > 1){
		int x = get_rand(2, n - 1), y = get_rand(2, n - 1);
		while(x == y) y = get_rand(2, n - 1);
		now ^= (calc(x) ^ calc(y));
		swap(p[x], p[y]);
		now ^= (calc(x) ^ calc(y));
	}
	for(int i = 1; i <= n; ++ i) write(p[i]), putchar(' ');
	putchar('\n');
}
signed main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int T = read();
	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: 3ms
memory: 16396kb

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

output:

5 1 2 3 4 6 
3 1 2 4 5 6 
6 2 3 4 5 1 
6 2 5 4 3 1 
3 2 4 5 6 1 
3 1 2 4 
3 6 2 5 4 1 
3 1 4 5 2 
1 2 3 5 6 4 
5 2 3 4 6 1 
4 2 3 1 
2 1 3 4 6 5 
1 2 6 5 4 3 
3 4 5 2 6 1 
2 3 5 1 6 4 
3 1 2 5 6 4 
5 1 4 2 6 3 
1 3 2 4 5 
4 1 3 2 
3 1 2 5 4 
1 3 2 4 
3 4 1 2 
5 1 3 4 2 
5 2 4 3 1 
5 1 2 6 4 3 
4 2 6...

result:

ok Answer correct!

Test #2:

score: 5
Accepted
time: 4ms
memory: 15776kb

input:

157
7 3 7
1 3
4 5
6 5
2 5
5 1
7 2
7 7 6
5 6
3 6
2 6
6 7
1 7
4 3
7 6 1
7 4
4 6
2 3
1 2
3 6
5 1
6 1 5
2 5
6 2
5 1
3 2
4 2
5 3 1
1 3
5 3
2 5
4 5
7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 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: 0ms
memory: 17800kb

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

result:

ok Answer correct!

Test #5:

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

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 4 3 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: 0ms
memory: 15920kb

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 
5 0 2 3 4 0 7 9 10 11 12 8 
7 6 2 6 5 1 11 9 10 8 12 4 
2 1 3 4 6 0 8 9 10 11 12 5 
10 5 2 3 4 7 6 8 9 11 12 7 
12 3 3 4 5 1 7 8 9 10 11 2 
6 11 2 3 4 6 0 8 1 1 10 
2 5 3 4 5 9 7 8 9 11 12 10 
9 11 2 3 4 6 7 8 10 1 5 
5 0 2 7 6 1 11 9 10 8 12 4 
8 1 3 4 5 6 7 9 10 11 2 
1...

result:

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

Subtask #3:

score: 0
Runtime Error

Test #11:

score: 0
Runtime Error

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:


result:


Subtask #4:

score: 0
Runtime Error

Test #18:

score: 0
Runtime Error

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:


result:


Subtask #5:

score: 0
Runtime Error

Test #25:

score: 0
Runtime Error

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:


result:


Subtask #6:

score: 0
Wrong Answer

Test #34:

score: 0
Wrong Answer
time: 5ms
memory: 19676kb

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 0 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 965 56 57 58 59 60 61 0 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 97 98 99 100 101 ...

result:

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

Subtask #7:

score: 0
Skipped

Dependency #2:

0%