4907 | 2023-04-06 16:54:50 | horvathabel | Energiatakarékos ellenőrzés | python3 | Runtime error 0/100 | 17ms | 13764 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 | Runtime error | 17ms | 10740 KiB | ||||
2 | Runtime error | 17ms | 10992 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Runtime error | 17ms | 11228 KiB | ||||
4 | Runtime error | 17ms | 11464 KiB | ||||
5 | Runtime error | 17ms | 11488 KiB | ||||
6 | Runtime error | 17ms | 11448 KiB | ||||
7 | Runtime error | 17ms | 11736 KiB | ||||
subtask3 | 0/15 | ||||||
8 | Runtime error | 17ms | 11828 KiB | ||||
9 | Runtime error | 17ms | 11840 KiB | ||||
10 | Runtime error | 17ms | 12316 KiB | ||||
11 | Runtime error | 17ms | 12336 KiB | ||||
12 | Runtime error | 16ms | 12344 KiB | ||||
13 | Runtime error | 17ms | 12404 KiB | ||||
14 | Runtime error | 17ms | 12424 KiB | ||||
subtask4 | 0/15 | ||||||
15 | Runtime error | 16ms | 12532 KiB | ||||
16 | Runtime error | 17ms | 12748 KiB | ||||
17 | Runtime error | 17ms | 12508 KiB | ||||
18 | Runtime error | 17ms | 12544 KiB | ||||
19 | Runtime error | 17ms | 12756 KiB | ||||
20 | Runtime error | 17ms | 12948 KiB | ||||
21 | Runtime error | 17ms | 12808 KiB | ||||
subtask5 | 0/65 | ||||||
22 | Runtime error | 17ms | 12512 KiB | ||||
23 | Runtime error | 17ms | 12976 KiB | ||||
24 | Runtime error | 17ms | 12992 KiB | ||||
25 | Runtime error | 17ms | 13088 KiB | ||||
26 | Runtime error | 17ms | 13304 KiB | ||||
27 | Runtime error | 17ms | 13288 KiB | ||||
28 | Runtime error | 17ms | 13444 KiB | ||||
29 | Runtime error | 17ms | 13216 KiB | ||||
30 | Runtime error | 17ms | 13256 KiB | ||||
31 | Runtime error | 17ms | 13300 KiB | ||||
32 | Runtime error | 17ms | 13200 KiB | ||||
33 | Runtime error | 17ms | 13184 KiB | ||||
34 | Runtime error | 17ms | 13196 KiB | ||||
35 | Runtime error | 17ms | 12972 KiB | ||||
36 | Runtime error | 17ms | 13372 KiB | ||||
37 | Runtime error | 17ms | 13484 KiB | ||||
38 | Runtime error | 17ms | 13652 KiB | ||||
39 | Runtime error | 17ms | 13764 KiB | ||||
40 | Runtime error | 17ms | 13752 KiB |