# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
528236 | Leo121 | 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 "grader.h"
#include <bits/stdc++.h>
#define forn(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int lim = 1e6;
vi graph[lim];
int pesos[lim];
bool visitado[lim];
ll mayor = LLONG_MAX, res = 0;
ll pesosub[lim];
int padre[lim];
ll dfs(int u){
pesosub[u] = (ll) pesos[u];
for(int v : graph[u]){
if(!visitados[v]){
padre[v] = u;
visitados[v] = 1;
pesosub[u] += dfs(v);
}
}
return pesosub;
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
ll pesototal = 0;
forn(i, 0, N - 1){
pesos[i] = pp[i];
pesototal += (ll) pp[i];
visitado[i] = 0;
pesosub[i] = 0;
}
forn(i, 0, N - 2){
graph[S[i]].pb(D[i]);
graph[D[i]].pb(S[i]);
}
visitado[0] = 1;
padre[0] = 0;
dfs(0);
ll minimo = INT_MAX, aux = 0, sumaaux;
int res = 0;
for(int i : graph[0]){
aux = max(aux, pesosub[i]);
}
minimo = aux;
forn(i, 1, N - 1){
aux = 0;
for(int j : graph[i]){
if(padre[j] == i){
aux = max(aux, pesosub[j]);
}
}
aux = max(aux, pesototal - pesosub[i]);
if(mayor >= aux){
mayor = aux;
res = i;
}
}
return res;
}