1241 | 2022-03-28 17:50:05 | k_balint | Energiatakarékos ellenőrzés | cpp14 | Accepted 100/100 | 79ms | 44828 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int c=1e5+5;
vector<int> adj[c];
ll dp[c][2];
int sz[c];
void dfs(int v, int p){
sz[v]=1;
for(int x:adj[v]){
if(x!=p){
dfs(x,v);
sz[v]+=sz[x];
dp[v][0]+=min(dp[x][0]+8, dp[x][1]+2*sz[x]);
dp[v][1]+=dp[x][1]+2*sz[x];
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin>>n;
for(int i=1;i<n;i++){
int a,b; cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1,0);
cout << min(dp[1][0],dp[1][1]) << endl;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 4ms | 6604 KiB | ||||
2 | Accepted | 79ms | 18144 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 37ms | 16368 KiB | ||||
4 | Accepted | 37ms | 17124 KiB | ||||
5 | Accepted | 35ms | 17908 KiB | ||||
6 | Accepted | 37ms | 18656 KiB | ||||
7 | Accepted | 39ms | 19444 KiB | ||||
subtask3 | 15/15 | ||||||
8 | Accepted | 3ms | 11596 KiB | ||||
9 | Accepted | 3ms | 11608 KiB | ||||
10 | Accepted | 4ms | 11608 KiB | ||||
11 | Accepted | 3ms | 11612 KiB | ||||
12 | Accepted | 3ms | 11616 KiB | ||||
13 | Accepted | 4ms | 11616 KiB | ||||
14 | Accepted | 3ms | 11620 KiB | ||||
subtask4 | 15/15 | ||||||
15 | Accepted | 3ms | 11632 KiB | ||||
16 | Accepted | 3ms | 11628 KiB | ||||
17 | Accepted | 3ms | 11636 KiB | ||||
18 | Accepted | 3ms | 11636 KiB | ||||
19 | Accepted | 3ms | 11648 KiB | ||||
20 | Accepted | 4ms | 11644 KiB | ||||
21 | Accepted | 3ms | 11656 KiB | ||||
subtask5 | 65/65 | ||||||
22 | Accepted | 61ms | 23264 KiB | ||||
23 | Accepted | 75ms | 24340 KiB | ||||
24 | Accepted | 64ms | 25552 KiB | ||||
25 | Accepted | 59ms | 26708 KiB | ||||
26 | Accepted | 59ms | 27864 KiB | ||||
27 | Accepted | 79ms | 38568 KiB | ||||
28 | Accepted | 75ms | 42268 KiB | ||||
29 | Accepted | 68ms | 36160 KiB | ||||
30 | Accepted | 65ms | 34576 KiB | ||||
31 | Accepted | 71ms | 33740 KiB | ||||
32 | Accepted | 67ms | 34612 KiB | ||||
33 | Accepted | 63ms | 35756 KiB | ||||
34 | Accepted | 39ms | 34536 KiB | ||||
35 | Accepted | 41ms | 35704 KiB | ||||
36 | Accepted | 41ms | 36944 KiB | ||||
37 | Accepted | 54ms | 38340 KiB | ||||
38 | Accepted | 56ms | 40160 KiB | ||||
39 | Accepted | 54ms | 43504 KiB | ||||
40 | Accepted | 54ms | 44828 KiB |