# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
988911 | Ice_man | 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.
/**
____ ____ ____ __________________ ____ ____ ____
||I || ||c || ||e || || || ||M || ||a || ||n ||
||__|| ||__|| ||__|| ||________________|| ||__|| ||__|| ||__||
|/__\| |/__\| |/__\| |/________________\| |/__\| |/__\| |/__\|
*/
#include <iostream>
#include <chrono>
#include "traffic.h"
#include <map>
#include <vector>
#define maxn 1000005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;
#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")
#pragma GCC target("avx2")
using namespace std;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;
typedef pair <ll , ll> pll;
typedef pair <int , ll> pil;
typedef pair <ll , int> pli;
typedef long double pd;
std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;
double timePassed()
{
using namespace std::chrono;
currT = high_resolution_clock::now();
double time = duration_cast<duration<double>>(currT - startT).count();
return time * TIME_MULT;
}
ll dp[maxn] , sum[maxn];
vector <int> v[maxn];
void dfs(int node , int _par)
{
for(int nb : v[node])
{
if(nb == _par)
continue;
dfs(nb , node);
sum[node] += sum[nb];
dp[node] = max(dp[node] , sum[node]);
}
}
int LocateCenter(int n , int p[] , int s[] , int d[])
{
ll _sum = 0LL;
for(int i = 0; i < n; i++)
_sum += p[i] , sum[i] = p[i];
for(int i = 0; i < n; i++)
v[s[i]].pb(d[i]) , v[d[i]].pb(s[i]);
dfs(0 , -1);
for(int i = 0; i < n; i++)
dp[i] = max(dp[i] , _sum - sum[i]);
int ans = 0;
for(int i = 1; i < n; i++)
if(dp[i] < dp[ans])
ans = i;
return ans;
}