Submission #995624

#TimeUsernameProblemLanguageResultExecution timeMemory
995624mindiyakTraffic (IOI10_traffic)C++14
100 / 100
1097 ms197992 KiB
#include "traffic.h" #include <bits/stdc++.h> #include <string> #include <iostream> #include <cmath> #include <numeric> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<int, int> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; typedef vector<ld> vd; typedef vector<long long> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define FOR(i, a, b) for (ll i = a; i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define len(x) (int)(x).size() #define mp make_pair #define pb push_back #define F first #define nl endl #define S second #define lb lower_bound #define ub upper_bound #define aint(x) x.begin(), x.end() #define raint(x) x.rbegin(), x.rend() #define ins insert const int MOD = 1000000007; vvl paths(1e6 + 10); vvl children(1e6 + 10); vpi level(1e6+10); vi parent(1e6+10); void dfs(int pos,int height,int visited){ level[pos] = {height,pos}; for(auto e:paths[pos]){ if(e == visited)continue; parent[e] = pos; dfs(e,height+1,pos); } } int LocateCentre(int N, int pp[], int S[], int D[]) { ll sum = 0; ll ans = 9e18; int anspos = -1; FOR(i,0,N)sum += pp[i]; paths = vvl(N,vl()); children = vvl(N,vl()); level = vpi(N); parent = vi(N,-1); FOR(i,0,N-1){ paths[S[i]].pb(D[i]); paths[D[i]].pb(S[i]); } dfs(0,0,-1); sort(level.rbegin(),level.rend()); FOR(i,0,N){ ll a = level[i].S; ll temp3 = -1; ll temp = sum - pp[a], temp2 = pp[a]; for(auto j:children[a]){ temp3 = max(temp3,j); temp -= j; temp2 += j; } children[a].pb(temp); temp3 = max(temp3,temp); if(ans > temp3)anspos = a; ans = min(ans,temp3); if(a == 0)continue; children[parent[a]].pb(temp2); } return anspos; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...