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;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e6+7;
const ll INF=1e18+7;
vector<int>V[LIM];
ll T[LIM], dp[LIM], oc[LIM], sum;
void DFS(int x, int o) {
dp[x]=T[x];
for(auto i : V[x]) if(i!=o) {
oc[i]=x;
DFS(i, x);
dp[x]+=dp[i];
}
}
int LocateCentre(int n, int pp[], int S[], int D[]) {
rep(i, n) {
T[i]=pp[i];
sum+=T[i];
}
rep(i, n-1) {
V[S[i]].pb(D[i]);
V[D[i]].pb(S[i]);
}
DFS(0, 0);
pair<ll,ll>ans={INF, INF};
rep(i, n) {
ll ma=sum-dp[i];
for(auto j : V[i]) if(j!=oc[i]) ma=max(ma, dp[j]);
pair<ll,ll>p={ma, i};
ans=min(ans, p);
}
return ans.nd;
}
# | 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... |