# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
298552 | aloo123 | 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 <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#include "traffic.h"
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
const ll INF = 1e12;
const ll N =(1e6+5); // TODO : change value as per problem
const ll MOD = 1e9+7;
vector<int> adj[N];
int sub[N];
int a[N];
void dfs(int u,int p){
sub[u] = a[u];
for(auto v:adj[u]){
if(v != p){
dfs(v,u);
sub[u] += sub[v];
}
}
}
int LocateCentre(int n,int p[],int s[],int d[]){
for(int i = 0;i<n;i++){
a[i+1] = p[i];
}
for(int i =0;i<n-1;i++){
int u = s[i],v = d[i];
u++;
v++;
adj[u].pb(v);
adj[v].pb(u);
}
int ans = INF,x = -1;
for(int i = 1;i <= n;i++){
dfs(i,0);
int ma = 0;
for(auto v:adj[i]){
ma = max(ma,sub[v]);
}
if(ma < ans){
ans = ma;
x = i;
}
}
x--;
return x;
}
// void solve(){
// }
// signed main(){
// ios_base::sync_with_stdio(0);
// cin.tie(NULL);
// // freopen(".in","r",stdin);freopen(".out","w",stdout);
// int n;
// cin >> n;
// int p[n];
// for(int i =0;i<n;i++){
// cin >> p[i];
// }
// int s[n-1];
// int d[n-1];
// for(int i =0;i<n-1;i++){
// cin >> s[i] >> d[i];
// }
// cout << LocateCentre(n,p,s,d) << endl;
// }