1209 | 2022-03-22 20:56:25 | Zoli9 | Energiatakarékos ellenőrzés | cpp11 | Accepted 100/100 | 90ms | 45828 KiB |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> G[100009];
bool b[100009];
long long ans_greedy[100009];
long long ans[100009];
long long children[100009];
void dfs(int x)
{
b[x]=true;
children[x]=1;
for(int nb: G[x])
{
if(!b[nb])
{
dfs(nb);
children[x]+=children[nb];
ans_greedy[x]+=(2*children[nb]+ans_greedy[nb]);
ans[x]+=min(2*children[nb]+ans_greedy[nb], 8+ans[nb]);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1; i<n; i++)
{
int a, b;
cin>>a>>b;
G[a].push_back(b);
G[b].push_back(a);
}
dfs(1);
cout<<ans[1]<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 4ms | 6616 KiB | ||||
2 | Accepted | 71ms | 19116 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 41ms | 17364 KiB | ||||
4 | Accepted | 43ms | 18116 KiB | ||||
5 | Accepted | 43ms | 18904 KiB | ||||
6 | Accepted | 41ms | 19528 KiB | ||||
7 | Accepted | 43ms | 20440 KiB | ||||
subtask3 | 15/15 | ||||||
8 | Accepted | 3ms | 11612 KiB | ||||
9 | Accepted | 3ms | 11616 KiB | ||||
10 | Accepted | 3ms | 11616 KiB | ||||
11 | Accepted | 4ms | 11624 KiB | ||||
12 | Accepted | 3ms | 11628 KiB | ||||
13 | Accepted | 3ms | 11636 KiB | ||||
14 | Accepted | 3ms | 11640 KiB | ||||
subtask4 | 15/15 | ||||||
15 | Accepted | 4ms | 11640 KiB | ||||
16 | Accepted | 3ms | 11644 KiB | ||||
17 | Accepted | 3ms | 11648 KiB | ||||
18 | Accepted | 4ms | 11648 KiB | ||||
19 | Accepted | 3ms | 11656 KiB | ||||
20 | Accepted | 3ms | 11660 KiB | ||||
21 | Accepted | 3ms | 11664 KiB | ||||
subtask5 | 65/65 | ||||||
22 | Accepted | 64ms | 24248 KiB | ||||
23 | Accepted | 68ms | 25408 KiB | ||||
24 | Accepted | 61ms | 26556 KiB | ||||
25 | Accepted | 63ms | 27716 KiB | ||||
26 | Accepted | 70ms | 28868 KiB | ||||
27 | Accepted | 86ms | 39572 KiB | ||||
28 | Accepted | 87ms | 43272 KiB | ||||
29 | Accepted | 76ms | 37144 KiB | ||||
30 | Accepted | 90ms | 35568 KiB | ||||
31 | Accepted | 67ms | 34680 KiB | ||||
32 | Accepted | 75ms | 35672 KiB | ||||
33 | Accepted | 65ms | 36760 KiB | ||||
34 | Accepted | 41ms | 35532 KiB | ||||
35 | Accepted | 43ms | 36700 KiB | ||||
36 | Accepted | 46ms | 37856 KiB | ||||
37 | Accepted | 46ms | 39352 KiB | ||||
38 | Accepted | 52ms | 41716 KiB | ||||
39 | Accepted | 52ms | 44724 KiB | ||||
40 | Accepted | 57ms | 45828 KiB |