이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef DEBUG
#include <traffic.h>
#endif
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5, inf = 2e9;
vector<int> adj[maxn];
int down[maxn], up[maxn], v[maxn], n, con[maxn];
void dfs(int node, int p) {
    for (int i : adj[node]) {
        if (i != p) {
            dfs(i, node);
            int cur = down[i] + v[i];
            down[node] += cur;
            con[node] = max(con[node], cur);
        }
    }
}
int LocateCentre(int cur_n, int cur_p[], int s[], int d[]) {
    n = cur_n;
    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) {
        v[i] = cur_p[i];
    }
    dfs(0, -1);
    for (int i = 0; i < n; ++i) {
        con[i] = max(con[i], down[0] - down[i] - v[i]);
    }
    pair<int, int> sol = {inf, 0};
    for (int i = 0; i < n; ++i) {
        sol = min(sol, make_pair(con[i], i));
    }
    return sol.second;
}
#ifdef DEBUG
int main() {
    int n = 5, p[5]{3, 5, 8, 10, 9}, s[4]{0, 1, 2, 3}, d[4]{1, 2, 3, 4};
    cout << LocateCentre(n, p, s, d) << "\n";
}
#endif
| # | 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... |