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 "traffic.h"
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pii pair <int, int>
#define pb push_back
#define F first
#define S second
#define ll long long
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 1000005;
const int mod = 1e9 + 7;
vector<int> a[N];
int w[N], dis[N], al, ans = INT_MAX, res;
void DFS(int node, int par){
dis[node] = w[node];
for(int i : a[node]){
if(i == par) continue;
DFS(i, node);
dis[node] += dis[i];
}
}
void get(int node, int par){
int cur = al - dis[node];
for(int i : a[node]){
if(i == par) continue;
cur = max(cur, dis[i]);
get(i, node);
}
if(cur < ans) {
ans = cur;
res = node;
}
}
int LocateCentre(int n, int r[], int to[], int from[]) {
for(int i = 0; i < n - 1; i++){
a[to[i]].pb(from[i]);
a[from[i]].pb(to[i]);
}
for(int i = 0; i < n; i++){
dis[i] = -1;
w[i] = r[i];
}
DFS(0, 0);
al = dis[0];
get(0, 0);
return res;
}
# | 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... |