50092023-04-09 11:03:37Babják PéterEnergiatakarékos ellenőrzéscpp11Accepted 100/100133ms35052 KiB
#include <bits/stdc++.h> 
#define MAXN 101000
using namespace std;
int n,p[MAXN],dp[MAXN],sub[MAXN];
vector<int>s[MAXN];
vector<int>c[MAXN];
void dfs(int v)
{
	for(int k:s[v])
	{
		if(p[v]!=k)
		{
			p[k]=v;
			dfs(k);
			sub[v]+=sub[k]+1;
			dp[v]+=min(dp[k]+(sub[k]+1)*2,dp[k]+8);
		}
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		s[a].push_back(b);
		s[b].push_back(a);
	}
	dfs(1);
	cout<<dp[1]<<'\n';
    return 0;
}

SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted6ms11360 KiB
2Accepted97ms20612 KiB
subtask25/5
3Accepted71ms19480 KiB
4Accepted70ms19692 KiB
5Accepted74ms19976 KiB
6Accepted74ms19816 KiB
7Accepted71ms20180 KiB
subtask315/15
8Accepted6ms12620 KiB
9Accepted6ms12652 KiB
10Accepted6ms12876 KiB
11Accepted7ms13088 KiB
12Accepted6ms13072 KiB
13Accepted6ms13204 KiB
14Accepted6ms13416 KiB
subtask415/15
15Accepted6ms13428 KiB
16Accepted6ms13552 KiB
17Accepted6ms13788 KiB
18Accepted6ms13640 KiB
19Accepted6ms13644 KiB
20Accepted6ms13744 KiB
21Accepted6ms13796 KiB
subtask565/65
22Accepted94ms22552 KiB
23Accepted114ms22576 KiB
24Accepted118ms22596 KiB
25Accepted94ms22548 KiB
26Accepted93ms22804 KiB
27Accepted101ms32584 KiB
28Accepted133ms35052 KiB
29Accepted101ms27920 KiB
30Accepted97ms25260 KiB
31Accepted94ms23080 KiB
32Accepted94ms23112 KiB
33Accepted94ms23112 KiB
34Accepted86ms22388 KiB
35Accepted89ms22476 KiB
36Accepted86ms22584 KiB
37Accepted92ms22932 KiB
38Accepted92ms23664 KiB
39Accepted90ms24360 KiB
40Accepted93ms24280 KiB