This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
#define ll long long
const int maxN = 1e6;
vector<int> adj[maxN];
int people[maxN];
int children[maxN];
int total;
void DFS(int P[], int src, int par) {
ll ret = 0;
for (int x : adj[src]) {
if (x != par) {
DFS(P, x, src);
children[src] += children[x];
people[src] = max(people[src], children[x]);
}
}
people[src] = max(people[src], total - children[src] - P[src]);
children[src] += P[src];
}
int LocateCentre(int N, int P[], int S[], int D[]) {
ll minCongestion = 2e9;
int ans = -1;
total = accumulate(P, P + N, 0);
for (int i = 0; i < N - 1; i++) {
adj[S[i]].push_back(D[i]);
adj[D[i]].push_back(S[i]);
}
DFS(P, 0, -1);
for (int i = 0; i < N; i++) {
ll congestionHere = people[i];
if (congestionHere < minCongestion) {
minCongestion = congestionHere;
ans = i;
}
}
return ans;
}
Compilation message (stderr)
traffic.cpp: In function 'void DFS(int*, int, int)':
traffic.cpp:16:8: warning: unused variable 'ret' [-Wunused-variable]
16 | ll ret = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |