52392023-04-23 16:48:53szilEnergiatakarékos ellenőrzéscpp14Wrong answer 0/10078ms27964 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 = g[x].size() - (x != 1);
	for(int i : g[x]){
		if(i==p)continue;
		r += dfs(i, x);
	}
	ans += min(8, r*2);
	return r;
}

int dfs2(int x, int p = -1){
	int r = (x == 1 ? 2 : (g[x].size()-1)*2);
	for(int i : g[x]){
		if(i==p)continue;
		r += dfs2(i, x);
	}
	ans += min(8*(int)(g[x].size()), r);
	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);
	}
	dfs2(1);
	cout<<ans<<"\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted4ms6668 KiB
2Wrong answer46ms13408 KiB
subtask20/5
3Wrong answer32ms13980 KiB
4Wrong answer32ms13936 KiB
5Wrong answer32ms14072 KiB
6Wrong answer32ms14172 KiB
7Wrong answer32ms14384 KiB
subtask30/15
8Wrong answer4ms7952 KiB
9Wrong answer4ms8140 KiB
10Wrong answer4ms8316 KiB
11Wrong answer4ms8512 KiB
12Accepted4ms8528 KiB
13Wrong answer4ms8488 KiB
14Accepted4ms8760 KiB
subtask40/15
15Wrong answer4ms8824 KiB
16Wrong answer4ms8880 KiB
17Wrong answer4ms9004 KiB
18Wrong answer4ms8912 KiB
19Wrong answer4ms8908 KiB
20Wrong answer4ms8964 KiB
21Accepted4ms9216 KiB
subtask50/65
22Wrong answer46ms15612 KiB
23Wrong answer45ms15560 KiB
24Wrong answer46ms15568 KiB
25Wrong answer45ms15568 KiB
26Wrong answer45ms15836 KiB
27Wrong answer52ms25476 KiB
28Wrong answer78ms27964 KiB
29Wrong answer61ms20796 KiB
30Wrong answer57ms18172 KiB
31Wrong answer59ms16064 KiB
32Wrong answer46ms16088 KiB
33Wrong answer52ms16040 KiB
34Accepted35ms16716 KiB
35Accepted43ms16924 KiB
36Wrong answer35ms17092 KiB
37Wrong answer37ms17060 KiB
38Wrong answer39ms17220 KiB
39Wrong answer37ms17268 KiB
40Wrong answer46ms17096 KiB