# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
775591 | DobromirAngelov | Traffic (IOI10_traffic) | C++14 | 0 ms | 0 KiB |
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>
#include "traffic.h"
using namespace std;
const int MAXN=1e6+5;
const int INF=2e9+5;
int a[MAXN];
vector<int> adj[MAXN];
int subtr[MAXN];
int dfs(int v,int par)
{
subtr[v]=a[v];
for(int i=0;i<adj[v].size();i++)
{
if(adj[v][i]==par) continue;
subtr[v]+=dfs(adj[v][i], v);
}
return subtr[v];
}
void LocateCentre(int n,int w[],int u[],int v[])
{
for(int i=0;i<n;i++)
{
a[i]=w[i];
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0,-1);
int ans=-1, best=INF;
for(int i=0;i<n;i++)
{
int curMax=subtr[0]-subtr[i];
for(int j=0;j<adj[i].size();j++)
{
curMax=max(curMax, subtr[adj[i][j]]);
}
if(curMax<best)
{
best=curMax;
ans=i;
}
}
return ans;
}