ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#212808 | #3829. C | Jacken | 10 | 40ms | 6772kb | C++11 | 518b | 2024-10-20 11:40:47 | 2024-10-20 12:45:13 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
vector<int>a[N];
int sum = 0;
void dfs(int x,int cnt,int fa)
{
int flag = 0;
for(int i = 0;i<a[x].size();i++)
{
int v = a[x][i];
if(v!=fa)
{
flag = 1;
dfs(v,cnt+1,x);
}
}
if(flag == 0)
{
sum+=cnt;
}
}
int main()
{
int n;
scanf("%d",&n);
for(int i = 1;i<=n-1;i++)
{
int x,y;
scanf("%d %d",&x,&y);
a[x].push_back(y);
a[y].push_back(x);
}
dfs(1,0,0);
printf("%d",sum);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
5 3 1 1 5 2 4 5 4
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
5 5 1 1 4 4 2 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
5 4 5 4 3 4 1 4 2
output:
6
result:
ok 1 number(s): "6"
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 3580kb
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:
534
result:
wrong answer 1st numbers differ - expected: '167', found: '534'
Subtask #3:
score: 0
Wrong Answer
Test #10:
score: 0
Wrong Answer
time: 0ms
memory: 3608kb
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:
17986
result:
wrong answer 1st numbers differ - expected: '1893', found: '17986'
Subtask #4:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 38ms
memory: 6772kb
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
Runtime Error
Test #22:
score: 0
Runtime Error
input:
1000000 198444 939986 569807 470692 847908 557044 739959 80274 772656 222835 832266 382872 267873 10...