5377 | 2023-04-27 06:29:33 | anon | Energiatakarékos ellenőrzés | cpp17 | Accepted 100/100 | 64ms | 33412 KiB |
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define xx first
#define yy second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
typedef long long ll;
using namespace std;
const double PI = acos(-1);
const ll INF = 1LL << 62;
vector<vector<ll>> g;
vector<ll> sol, tme;
vector<bool> vis;
void dfs(ll r)
{
vis[r] = true;
if(sz(g[r]) == 1 && r != 1)
{
sol[r] = 0;
tme[r] = 1;
return;
}
for(auto x : g[r])
{
if(!vis[x])
dfs(x);
}
sol[r] = 0;
tme[r] = sz(g[r]);
for(auto x : g[r])
{
if(sol[x] == -1)
continue;
sol[r] += min(1 + sol[x] + tme[x], 8 + sol[x]);
tme[r] += tme[x];
}
}
int main()
{
FastIO;
ll i, a, b, N;
cin >> N;
g.resize(N + 1);
for(i = 1; i < N; i++)
{
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
sol.resize(N + 1);
tme.resize(N + 1);
vis.resize(N + 1);
fill(all(sol), -1);
dfs(1);
cout << sol[1] << endl;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1888 KiB | ||||
2 | Accepted | 50ms | 17188 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 35ms | 17888 KiB | ||||
4 | Accepted | 37ms | 17832 KiB | ||||
5 | Accepted | 39ms | 18312 KiB | ||||
6 | Accepted | 35ms | 18120 KiB | ||||
7 | Accepted | 37ms | 18736 KiB | ||||
subtask3 | 15/15 | ||||||
8 | Accepted | 3ms | 3240 KiB | ||||
9 | Accepted | 2ms | 3332 KiB | ||||
10 | Accepted | 3ms | 3328 KiB | ||||
11 | Accepted | 3ms | 3328 KiB | ||||
12 | Accepted | 3ms | 3328 KiB | ||||
13 | Accepted | 3ms | 3452 KiB | ||||
14 | Accepted | 3ms | 3684 KiB | ||||
subtask4 | 15/15 | ||||||
15 | Accepted | 2ms | 3876 KiB | ||||
16 | Accepted | 2ms | 3968 KiB | ||||
17 | Accepted | 2ms | 4092 KiB | ||||
18 | Accepted | 2ms | 4172 KiB | ||||
19 | Accepted | 2ms | 4176 KiB | ||||
20 | Accepted | 3ms | 4280 KiB | ||||
21 | Accepted | 2ms | 4368 KiB | ||||
subtask5 | 65/65 | ||||||
22 | Accepted | 48ms | 19472 KiB | ||||
23 | Accepted | 52ms | 19508 KiB | ||||
24 | Accepted | 50ms | 19504 KiB | ||||
25 | Accepted | 48ms | 19588 KiB | ||||
26 | Accepted | 50ms | 19692 KiB | ||||
27 | Accepted | 64ms | 30360 KiB | ||||
28 | Accepted | 59ms | 33412 KiB | ||||
29 | Accepted | 54ms | 25368 KiB | ||||
30 | Accepted | 54ms | 22136 KiB | ||||
31 | Accepted | 52ms | 19576 KiB | ||||
32 | Accepted | 50ms | 19480 KiB | ||||
33 | Accepted | 50ms | 19440 KiB | ||||
34 | Accepted | 37ms | 20104 KiB | ||||
35 | Accepted | 37ms | 20044 KiB | ||||
36 | Accepted | 37ms | 20100 KiB | ||||
37 | Accepted | 37ms | 20648 KiB | ||||
38 | Accepted | 43ms | 20768 KiB | ||||
39 | Accepted | 45ms | 21192 KiB | ||||
40 | Accepted | 43ms | 20828 KiB |