# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
362288 | saifu | 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.
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----
#include "traffic.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define mod 1000000007
#define inf (int)1e18
const int mxn = 1e6+10;
vector<int> g[mxn];
int people[mxn];
int dp[mxn];
void dfs(int v, int p=-1){
dp[v] = people[v];
for(int u : g[v]){
if(u==p) continue;
dfs(u,v);
dp[v] += dp[u];
}
}
int LocateCentre (int n, int p[], int d[], int s[]){
for(int i=0;i<n;i++) people[i] = p[i];
for(int i=0;i<n-1;i++){
g[s[i]].push_back(d[i]);
g[d[i]].push_back(s[i]);
}
int mn = inf;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) dp[i] = 0;
dfs(i);
int mx = 0;
for(int u : g[i]){
mx = max(mx,dp[u]);
}
mn = min(mn,mx);
}
return mn;
}