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 <vector>
using namespace std;
const int maxN = 1000005;
int n, sz[maxN], bestDiff, bestCity, total;
vector <int> G[maxN];
void dfs(int nod, int tata) {
int currDiff = 0;
for (int vecin : G[nod]) {
if (vecin == tata) {
continue;
}
dfs(vecin, nod);
sz[nod] += sz[vecin];
currDiff = max(currDiff, sz[vecin]);
}
currDiff = max(currDiff, total - sz[nod]);
if (currDiff < bestDiff) {
bestDiff = currDiff;
bestCity = nod;
}
}
int LocateCentre(int N, int P[], int S[], int D[]) {
n = N;
for (int i = 0; i < n; i++) {
sz[i] += P[i];
total += P[i];
}
bestDiff = 2 * maxN;
for (int i = 0; i < n - 1; i++) {
G[S[i]].push_back(D[i]);
G[D[i]].push_back(S[i]);
}
dfs(0, 0);
return bestCity;
}
# | 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... |