QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#82399#4615. 榕树之心hellojim100 ✓585ms18136kbC++141.3kb2023-02-27 19:29:252023-02-27 19:29:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-27 19:29:44]
  • 评测
  • 测评结果:100
  • 用时:585ms
  • 内存:18136kb
  • [2023-02-27 19:29:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int W,T;
int n;
vector<int>g[N];
int sz[N],f[N],dep[N];
int son1[N],son2[N];
int ans[N]; 
void dfs1(int u,int fa){
	dep[u]=dep[fa]+1;
	sz[u]=1;
	son1[u]=son2[u]=0;
	for(auto v:g[u]){
		if(v==fa)continue;
		dfs1(v,u);
		sz[u]+=sz[v]; 
		if(sz[v]>sz[son1[u]]){
			son2[u]=son1[u];son1[u]=v;
		}
		else if(sz[v]>sz[son2[u]]){
			son2[u]=v;
		}
	} 
	int v=son1[u];
	if(sz[v]-2*f[v]<=sz[u]-sz[v]-1)f[u]=(sz[u]-1)/2;
	else f[u]=f[v]+sz[u]-sz[v]-1;
} 
int h;
void dfs2(int u,int fa){
	int tmp1=h;
	if(!h||sz[son2[u]]>sz[h])h=son2[u];
	int tmp2=h;
	if(!h||sz[son1[u]]>=sz[h])h=son1[u];
	int tmp3=h;
	if((n-dep[u])%2==0&&sz[h]-2*f[h]<=n-dep[u]-sz[h])ans[u]=1;
	else ans[u]=0; 
	for(auto v:g[u]){
		if(v==fa)continue;
		if(v==son1[u])h=tmp2;
		else h=tmp3;
		dfs2(v,u);
	}
	h=tmp1;
}
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++)g[i].clear();
	for(int i=1;i<n;i++){
		int x,y;cin>>x>>y;
		g[x].push_back(y);g[y].push_back(x);
	}
	dfs1(1,0);h=0;
	dfs2(1,0);
	if(W==3){
		cout<<ans[1]<<"\n";
	}
	else{
		for(int i=1;i<=n;i++)cout<<ans[i];cout<<"\n";
	}
}
int main(){
	cin.tie(0);cout.tie(0);
	ios::sync_with_stdio(0);
//	freopen("move.in","r",stdin);freopen("move.out","w",stdout);
	cin>>W>>T;
	while(T--)solve();
	return 0;
}



详细

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 1ms
memory: 7128kb

input:

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

output:

101010011110000
100010111101010
101101010010110
100111100100011
100110010011000
101011100110000
101011010110101
100101100010111
101110000100111
101010101011100
001011000010110
100110100000101
101100110000010
101110011010101
101110010010100
101010100111010
000100010011000
000000101100011
001100010100...

result:

ok 50 lines

Subtask #2:

score: 20
Accepted

Test #2:

score: 20
Accepted
time: 378ms
memory: 16752kb

input:

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

output:

010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101...

result:

ok 20 lines

Subtask #3:

score: 20
Accepted

Test #3:

score: 20
Accepted
time: 6ms
memory: 7276kb

input:

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

output:

0
0
1
0
1
1
1
0
1
1
0
0
1
0
0
0
0
1
1
0
0
0
0
0
1
0
0
0
1
0
1
0
0
0
1
0
1
0
1
0
0
1
1
1
1
0
0
1
1
1
1
0
1
1
0
0
1
1
0
1
1
0
1
1
1
1
0
0
1
1
0
0
0
0
1
0
0
1
1
1
0
1
0
0
0
0
0
0
1
0
1
0
0
0
0
1
0
1
0
1
1
1
0
1
1
0
1
0
1
0
0
1
0
0
0
1
0
0
1
0
0
0
1
1
1
0
1
0
0
1
1
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
1
1
0
0
...

result:

ok 200 lines

Subtask #4:

score: 20
Accepted

Test #4:

score: 20
Accepted
time: 7ms
memory: 5944kb

input:

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

output:

010110111010000110011010100101011101001110011100000001011011111101110011010111001010011100101010011100001001100000101111100010011111001101110101010100011110110000010011000000001101100101000011100111110111100110101011001111110001111100010110101110110110100100000111100111101000000111010001101010011110...

result:

ok 20 lines

Subtask #5:

score: 20
Accepted

Dependency #2:

100%
Accepted

Dependency #4:

100%
Accepted

Test #5:

score: 20
Accepted
time: 585ms
memory: 18136kb

input:

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

output:

011010010101010010000111011100001011100101101011100100110101011110000011100111010010111000010001001010101100000101100010101001111100011001011111001100011001100111110100011111101011111101101011110011011111000010011000011110000100000110001101100101100101000100011100010100011001011100110110101100110101...

result:

ok 20 lines

Extra Test:

score: 0
Extra Test Passed