# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
441671 | mate | 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>
#define int long long
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define INF LLONG_MAX
using namespace std;
const int NMAX=200001;
int p[NMAX],d[NMAX];
vector<int> g[NMAX];
void DFS(int v,int e=-1){
d[v]=p[v];
for(int u: g[v])
if(u!=e){
DFS(u,v);
d[v]+=d[u];
}
}
int mn=INF;
void dfs(int v,int e=-1){
int ans=d[1]-d[v];
for(int u: g[v])
if(u!=e){
dfs(u,v);
ans=max(ans,d[u]);
}
mn=min(mn,ans);
}
main(){
int n;
cin >> n;
for(int i=1;i<=n;i++)
cin >> p[i];
for(int i=1;i<n;i++){
int v,u;
cin >> v >> u;
g[v].pb(u);
g[u].pb(v);
}
DFS(1);
dfs(1);
cout << mn;
}