#include "traffic.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MX = 1e6+5;
int sum, sz[MX];
ii ans;
vector<int> G[MX];
void dfs(int u, int p) {
for (int v : G[u]) if (v != p)
dfs(v, u), sz[u] += sz[v];
}
void solve(int u, int p, int P[]) {
int up = sum-P[u], mx = 0;
for (int v : G[u]) if (v != p)
up -= sz[v], mx = max(sz[v], mx);
mx = max(up, mx);
if (mx < ans.f) ans = ii(mx, u);
for (int v : G[u]) if (v != p) dfs(v, u);
}
int LocateCentre(int N, int P[], int S[], int D[]) {
for (int i = 0; i < N-1; ++i)
G[S[i]].push_back(D[i]),
G[D[i]].push_back(S[i]);
for (int i = 0; i < N; ++i)
sum += P[i], sz[i] = P[i];
dfs(0, -1);
solve(0, -1, P);
return ans.s;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
23788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
23788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
23788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
23788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |