#include "traffic.h"
#include "bits/stdc++.h"
using namespace std;
const int mxN = 1e6 + 7;
int n, p[mxN], dp[mxN], tot;
vector<int> graph[mxN];
void dfs(int u, int par) {
dp[u] = p[u];
for (auto v : graph[u]) {
if (v != par) {
dfs(v, u);
dp[u] += dp[v];
}
}
}
int LocateCentre(int N, int P[], int S[], int D[]) {
n = N;
for (int i = 0; i < n; ++i) {
p[i] = P[i];
tot += p[i];
}
for (int i = 0; i < n - 1; ++i) {
graph[S[i]].push_back(D[i]);
graph[D[i]].push_back(S[i]);
}
dfs(0, -1);
int ans = INT_MAX;
for (int u = 0; u < n; ++u) {
ans = min(ans, max(tot - dp[u], dp[u] - p[u]));
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
Output is correct |
2 |
Incorrect |
14 ms |
23808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
Output is correct |
2 |
Incorrect |
14 ms |
23808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
Output is correct |
2 |
Incorrect |
14 ms |
23808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23756 KB |
Output is correct |
2 |
Incorrect |
14 ms |
23808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |