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>
using namespace std;
#define ll long long
vector<int> adj[1000000];
ll DFS(int P[], int src, int par) {
ll ret = 0;
for (int x : adj[src]) {
if (x != par) {
ret += DFS(P, x, src);
}
}
return P[src] + ret;
}
int LocateCentre(int N, int P[], int S[], int D[]) {
ll minCongestion = 2000000000;
int ans = -1;
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++) {
ll congestionHere = 0;
for (int c : adj[i]) {
congestionHere = max(congestionHere, DFS(P, c, i));
}
if (congestionHere < minCongestion) {
minCongestion = congestionHere;
ans = i;
}
}
return ans;
}
// int main() {
// int arr1[5] = {10, 10, 10, 20, 20};
// int arr2[4] = {0, 1, 2, 3};
// int arr3[4] = {2, 2, 3, 4};
// cout << LocateCentre(5, arr1, arr2, arr3) << endl;
// }
# | 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... |