#include "traffic.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
int n, *p, *s, *d, sz[N], sum_all = 0;
vector<int> adj[N];
int dfs_solve(int u, int par = -1){
int ans = INT_MAX, sum = 0, mx = 0;
for(int to: adj[u])
if(to != par){
ans = min(ans, dfs_solve(to, u));
mx = max(mx, sz[to]);
sum += sz[to];
}
mx = max(mx, sum_all - sum - p[u]);
ans = min(ans, mx);
return ans;
}
void dfs_sz(int u, int par = -1){
sz[u] = p[u];
for(int to: adj[u])
if(to != par){
dfs_sz(to, u);
sz[u] += sz[to];
}
}
int LocateCentre(int _n, int _p[], int _s[], int _d[]) {
n = _n, p = _p, s = _s, d = _d;
for(int i = 0; i < n - 1; ++i){
adj[s[i]].push_back(d[i]);
adj[d[i]].push_back(s[i]);
}
for(int i = 0; i < n; ++i)
sum_all += p[i];
dfs_sz(0);
return dfs_solve(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23732 KB |
Output is correct |
2 |
Incorrect |
15 ms |
23800 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23732 KB |
Output is correct |
2 |
Incorrect |
15 ms |
23800 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23732 KB |
Output is correct |
2 |
Incorrect |
15 ms |
23800 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23732 KB |
Output is correct |
2 |
Incorrect |
15 ms |
23800 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |