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 <bits/stdc++.h>
using namespace std;
long long dfs(int nodoActual, vector<vector<int>>& lista, int par, int P[]) {
long long ans = 0;
for (int vecino: lista[nodoActual]) {
if (vecino == par) continue;
ans += dfs(vecino, lista, nodoActual, P);
}
return ans+P[nodoActual];
}
int LocateCentre (int N, int P[], int S[], int D[]) {
vector<vector<int>> g(N, vector<int>());
for (int i = 0; i < N-1; ++i) {
g[S[i]].push_back(D[i]);
g[D[i]].push_back(S[i]);
}
long long maxi = 2e18+1, ans = -1;
for (int i = 0; i < N; ++i) {
long long cur = dfs(i, g, i, P);
if (cur < maxi) {
maxi = cur;
ans = i;
}
}
return ans;
}
# | 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... |