4908 | 2023-04-06 16:55:10 | horvathabel | Energiatakarékos ellenőrzés | cpp17 | Wrong answer 0/100 | 103ms | 27824 KiB |
#include <bits/stdc++.h>
using namespace std;
int p[100001];
int t[100001];
bool seen[100001];
int cnt=0;
int c[100001];
int ans=0;
vector<int>g[100001];
void dfs(int x){
if (!seen[x]){
seen[x]=true;
cnt++;
t[x]=cnt;
if (c[x]==1 && x!=1){
int a=x;
while (c[a]<3 && a!=1){
a=p[a];
cnt++;
ans+=cnt-t[a];
}
}
for (auto edge:g[x]){
if (!seen[edge]){
p[edge]=x;
dfs(edge);
}
}
c[x]=-1;
}
}
int main() {
int n;
cin>>n;
for (int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
c[a]++;
c[b]++;
}
dfs(1);
cout<<ans;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 4ms | 6672 KiB | ||||
2 | Wrong answer | 89ms | 15940 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Wrong answer | 67ms | 16584 KiB | ||||
4 | Wrong answer | 68ms | 16728 KiB | ||||
5 | Wrong answer | 67ms | 16944 KiB | ||||
6 | Wrong answer | 68ms | 16884 KiB | ||||
7 | Wrong answer | 67ms | 17112 KiB | ||||
subtask3 | 0/15 | ||||||
8 | Wrong answer | 4ms | 7936 KiB | ||||
9 | Wrong answer | 4ms | 8232 KiB | ||||
10 | Wrong answer | 4ms | 8532 KiB | ||||
11 | Wrong answer | 4ms | 8568 KiB | ||||
12 | Wrong answer | 4ms | 8612 KiB | ||||
13 | Wrong answer | 4ms | 8784 KiB | ||||
14 | Wrong answer | 4ms | 8740 KiB | ||||
subtask4 | 0/15 | ||||||
15 | Wrong answer | 4ms | 8780 KiB | ||||
16 | Wrong answer | 4ms | 9028 KiB | ||||
17 | Wrong answer | 4ms | 8940 KiB | ||||
18 | Wrong answer | 4ms | 9196 KiB | ||||
19 | Wrong answer | 4ms | 9152 KiB | ||||
20 | Wrong answer | 4ms | 9304 KiB | ||||
21 | Wrong answer | 4ms | 9152 KiB | ||||
subtask5 | 0/65 | ||||||
22 | Wrong answer | 90ms | 18168 KiB | ||||
23 | Wrong answer | 92ms | 18124 KiB | ||||
24 | Wrong answer | 90ms | 18148 KiB | ||||
25 | Wrong answer | 90ms | 18120 KiB | ||||
26 | Wrong answer | 90ms | 18152 KiB | ||||
27 | Wrong answer | 103ms | 25820 KiB | ||||
28 | Wrong answer | 101ms | 27824 KiB | ||||
29 | Wrong answer | 97ms | 21976 KiB | ||||
30 | Wrong answer | 94ms | 19972 KiB | ||||
31 | Wrong answer | 93ms | 18364 KiB | ||||
32 | Wrong answer | 93ms | 18264 KiB | ||||
33 | Wrong answer | 93ms | 18356 KiB | ||||
34 | Wrong answer | 82ms | 18888 KiB | ||||
35 | Wrong answer | 82ms | 18888 KiB | ||||
36 | Wrong answer | 79ms | 19068 KiB | ||||
37 | Wrong answer | 85ms | 19184 KiB | ||||
38 | Wrong answer | 86ms | 19192 KiB | ||||
39 | Wrong answer | 82ms | 19276 KiB | ||||
40 | Wrong answer | 86ms | 19224 KiB |