이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
 *      Author:  Richw818
 *      Created: 02.16.2023 15:28:46
**/
#include <bits/stdc++.h>
using namespace std;
int total = 0;
int center = -1, traffic = INT_MAX;
vector<vector<int>> adj;
vector<int> costs;
int dfs(int n, int p){
    int most = 0, totalChild = 0;
    for(int next : adj[n]){
        if(next != p){
            int val = dfs(next, n);
            most = max(most, val);
            totalChild += most;
        }
    }
    totalChild += costs[n];
    most = max(most, total - totalChild);
    if(most < traffic){
        center = n;
        traffic = most;
    }
    return totalChild;
}
int LocateCentre(int n, int p[], int s[], int d[]){
    adj.resize(n);
    costs.resize(n);
    for(int i = 0; i < n; i++) costs[i] = p[i];
    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(0, -1);
    return center;
}
// int main(){
//     ios_base::sync_with_stdio(false);
//     cin.tie(nullptr);
    
//     return 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... |