52402023-04-23 16:53:59szilEnergiatakarékos ellenőrzéscpp14Accepted 100/10061ms23204 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100001;

vector<int> g[MAXN];

int ans = 0;

int dfs(int x, int p = -1){
	int r = 1;
	for(int i : g[x]){
		if(i==p)continue;
		int c = dfs(i, x);
		r += c;
		ans += min(8, 2*c);
	}
	return r;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	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);
	}
	dfs(1);
	cout<<ans<<"\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted4ms6664 KiB
2Accepted43ms13300 KiB
subtask25/5
3Accepted34ms13856 KiB
4Accepted32ms14068 KiB
5Accepted32ms14164 KiB
6Accepted32ms14172 KiB
7Accepted34ms14340 KiB
subtask315/15
8Accepted4ms7764 KiB
9Accepted4ms7972 KiB
10Accepted4ms8280 KiB
11Accepted4ms8352 KiB
12Accepted4ms8308 KiB
13Accepted4ms8560 KiB
14Accepted4ms8896 KiB
subtask415/15
15Accepted4ms8736 KiB
16Accepted4ms8656 KiB
17Accepted4ms8720 KiB
18Accepted4ms8660 KiB
19Accepted4ms8660 KiB
20Accepted4ms8660 KiB
21Accepted4ms8920 KiB
subtask565/65
22Accepted50ms15560 KiB
23Accepted46ms15568 KiB
24Accepted45ms15728 KiB
25Accepted46ms15732 KiB
26Accepted45ms15708 KiB
27Accepted48ms21584 KiB
28Accepted50ms23204 KiB
29Accepted50ms18676 KiB
30Accepted46ms17016 KiB
31Accepted48ms15772 KiB
32Accepted61ms15704 KiB
33Accepted57ms15724 KiB
34Accepted35ms16256 KiB
35Accepted35ms16316 KiB
36Accepted43ms16568 KiB
37Accepted37ms16664 KiB
38Accepted39ms16864 KiB
39Accepted45ms16996 KiB
40Accepted39ms16820 KiB