QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#72708#2569. Kill All TermitesCSU2023#WA 4ms9128kbC++14836b2023-01-18 09:23:092023-01-18 09:23:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-18 09:23:11]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:9128kb
  • [2023-01-18 09:23:09]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define mk make_pair
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 3;
vector <int> G[N];
int n,ans;
int fa[N]; 
inline int read(){
	int v = 0,c = 1;char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') c = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		v = v * 10 + ch - 48;
		ch = getchar();
	}
	return v * c;
}
inline int dfs(int x,int f){
	int num = 0;
	if(!G[x].size()) return 1;
	for(auto y : G[x])
		num += dfs(y,x);
	if(num >= 2){
		ans++;
		return 0;	
	}
	else return num;
}
int main(){
	n = read();
	if(n <= 2){
		printf("1\n");
		return 0;
	}
	for(int i = 2;i <= n;++i){
		fa[i] = read();
		G[fa[i]].push_back(i);
	}
	dfs(1,0);
	printf("%d\n",ans);
    return 0;
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1


output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 4ms
memory: 8252kb

input:

2
1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 4ms
memory: 8116kb

input:

8
1 1 2 1 2 3 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 1ms
memory: 8220kb

input:

3
1 1

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 3ms
memory: 8168kb

input:

4
1 1 1

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 2ms
memory: 8684kb

input:

5
1 1 1 1

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 4ms
memory: 9128kb

input:

6
1 2 2 2 1

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 1ms
memory: 8288kb

input:

7
1 2 1 4 3 4

output:

1

result:

ok 1 number(s): "1"

Test #9:

score: 0
Accepted
time: 2ms
memory: 8168kb

input:

9
1 1 2 3 1 4 2 7

output:

2

result:

ok 1 number(s): "2"

Test #10:

score: 0
Accepted
time: 1ms
memory: 9056kb

input:

10
1 2 3 3 1 2 3 7 9

output:

2

result:

ok 1 number(s): "2"

Test #11:

score: 0
Accepted
time: 4ms
memory: 8724kb

input:

11
1 1 2 1 5 6 7 3 3 2

output:

2

result:

ok 1 number(s): "2"

Test #12:

score: 0
Accepted
time: 1ms
memory: 8296kb

input:

12
1 1 3 3 2 1 4 7 4 8 10

output:

2

result:

ok 1 number(s): "2"

Test #13:

score: 0
Accepted
time: 3ms
memory: 8620kb

input:

13
1 1 3 4 1 4 4 3 6 1 1 4

output:

2

result:

ok 1 number(s): "2"

Test #14:

score: 0
Accepted
time: 1ms
memory: 8456kb

input:

14
1 2 3 2 4 1 4 7 3 9 7 8 4

output:

3

result:

ok 1 number(s): "3"

Test #15:

score: 0
Accepted
time: 1ms
memory: 8172kb

input:

100
1 2 1 1 3 6 5 5 4 8 4 4 3 14 10 14 8 13 12 18 8 3 7 1 12 10 9 17 26 30 21 11 29 19 20 25 17 10 9 26 6 40 42 29 2 24 14 25 6 41 47 24 21 46 28 8 30 2 19 41 54 43 23 1 65 21 19 35 58 8 71 59 12 2 13 4 16 7 22 58 26 44 1 12 14 80 19 12 43 77 21 54 41 94 37 61 28 82 30

output:

19

result:

ok 1 number(s): "19"

Test #16:

score: 0
Accepted
time: 4ms
memory: 8852kb

input:

100
1 2 3 4 4 6 7 8 9 10 11 10 13 14 15 16 17 17 19 19 15 22 23 15 13 26 27 28 29 30 30 32 28 26 13 36 37 38 39 40 41 42 43 44 45 45 47 48 48 48 51 47 44 54 43 56 56 58 59 60 60 59 63 64 64 66 66 64 69 70 56 72 73 72 75 76 77 42 40 80 40 82 83 83 85 85 85 88 89 88 91 40 38 37 95 96 95 95 2

output:

17

result:

ok 1 number(s): "17"

Test #17:

score: 0
Accepted
time: 4ms
memory: 8180kb

input:

1000
1 2 3 3 5 6 7 8 9 10 11 12 11 14 15 16 16 18 19 19 21 22 23 22 21 26 27 28 29 30 31 28 27 27 35 26 37 38 39 40 41 42 43 44 41 40 47 39 18 50 51 52 53 54 55 56 57 58 59 60 60 58 57 64 65 66 67 66 65 70 71 72 73 72 64 76 76 78 79 80 56 82 18 84 84 86 86 88 88 14 14 92 14 94 94 96 96 98 98 100 101...

output:

169

result:

ok 1 number(s): "169"

Test #18:

score: 0
Accepted
time: 2ms
memory: 8332kb

input:

1000
1 2 2 2 2 2 7 2 2 2 2 2 2 2 15 15 15 2 2 2 21 1 23 23 25 25 23 1 1 1 31 31 31 31 31 31 31 1 39 40 39 42 43 42 42 42 39 39 39 50 50 39 39 54 54 39 57 57 39 60 60 60 60 60 60 39 67 67 69 67 67 67 67 39 75 75 77 77 75 75 75 39 39 39 85 39 39 39 39 39 91 91 93 39 95 95 95 98 98 95 95 95 103 103 105...

output:

152

result:

ok 1 number(s): "152"

Test #19:

score: -100
Wrong Answer
time: 1ms
memory: 8896kb

input:

1000
1 2 3 4 5 6 7 8 7 10 11 11 10 14 6 4 17 17 19 20 3 22 23 23 25 26 23 28 29 30 31 32 33 33 31 36 37 31 3 2 41 42 43 44 42 46 47 48 49 50 51 48 53 54 53 56 57 57 59 60 60 62 63 64 64 66 66 59 69 70 71 70 69 74 75 75 53 78 79 78 78 82 83 53 85 86 86 88 88 88 85 85 85 47 95 96 97 98 99 100 101 100 ...

output:

180

result:

wrong answer 1st numbers differ - expected: '181', found: '180'