UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212696#3829. Chuangyuhang0730ms56244kbC++11626b2024-10-20 09:46:072024-10-20 12:38:03

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
vector<int>V[1000000+5];
int n;
bool vis[1000000+5];
int c[1000000+5];
vector<int>Q;
void build(int root)
{
	if(V[root].size()==1) 
		Q.push_back(root);
	else
		for(auto p:V[root])
			if(!vis[p])
			{
				vis[p]=true;
				c[p]=c[root]+1;	
				build(p);
			}
			
} 
int main()
{
	scanf("%d",&n);
	int x,y;
	for(int i=1;i<n;i++)
	{
		scanf("%d %d",&x,&y);
		V[x].push_back(y);
		V[y].push_back(x);
	}
	c[1]=0;
	vis[1]=true;
	long long ans=0;
	build(1);
	for(auto p:Q)
		ans+=c[p]*1LL;
	printf("%lld",ans);
	return 0;
} 

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 0ms
memory: 24688kb

input:

5
3 1
1 5
2 4
5 4

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

5
5 1
1 4
4 2
2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: -10
Wrong Answer
time: 7ms
memory: 24688kb

input:

5
4 5
4 3
4 1
4 2

output:

0

result:

wrong answer 1st numbers differ - expected: '6', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 10ms
memory: 24692kb

input:

100
63 38
17 33
44 12
9 66
21 98
2 49
68 67
75 42
78 25
92 6
67 17
90 19
48 51
83 9
20 94
68 4
64 58...

output:

0

result:

wrong answer 1st numbers differ - expected: '167', found: '0'

Subtask #3:

score: 0
Wrong Answer

Test #10:

score: 0
Wrong Answer
time: 4ms
memory: 24720kb

input:

1000
228 978
939 994
911 13
8 806
680 958
779 832
673 924
627 806
354 476
320 218
766 848
171 944
90...

output:

0

result:

wrong answer 1st numbers differ - expected: '1893', found: '0'

Subtask #4:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 47ms
memory: 28564kb

input:

100000
44881 88880
79640 18741
56510 31493
27649 50461
7015 98523
26337 91384
17594 52397
37312 3409...

output:

16429820

result:

wrong answer 1st numbers differ - expected: '199052', found: '16429820'

Subtask #5:

score: 0
Wrong Answer

Test #22:

score: 0
Wrong Answer
time: 658ms
memory: 56244kb

input:

1000000
198444 939986
569807 470692
847908 557044
739959 80274
772656 222835
832266 382872
267873 10...

output:

0

result:

wrong answer 1st numbers differ - expected: '1994506', found: '0'