# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344565 | DavidZ122 | 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>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
typedef long long ll;
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define F1R(i,a) FOR(i,1,a)
#define ROF(i,a,b) for ( i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define f first
#define s second
#define mp make_pair
#define pb push_back
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if (sz(name)) {
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
bool cmp(const pair<pair<int,int>,int>&a, const pair<pair<int,int>,int> &b)
{
return a.s>b.s;
}
bool cmp2(const pair<pair<int,int>,int>&a, const pair<pair<int,int>,int> &b)
{
return a.f.s>b.f.s;
}
const int SZ=1e6+1;
const int MOD=1e9+7;
int fans[SZ];
vi adj[SZ];
ll dfs(int node)
{
ll ans=fans[node];
trav(x, adj[node])
{
ans+=dfs(x);
}
return ans;
}
ll solve(int node)
{
ll m=INT_MAX;
trav(x, adj[node])
{
m=fmin(m, dfs(x));
}
return m;
}
int main() {
FIO;
ll n; cin>>n;
F0R(i, n) cin>>fans[i];
F0R(i, n-1)
{
ll a, b; cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
ll ans=0, ansMin=INT_MAX;
F0R(i, n)
{
ll a=solve(i);
if(a<ansMin)
{
ans=i;
ansMin=a;
}
}
cout<<ans+1<<endl;
}