제출 #528245

#제출 시각아이디문제언어결과실행 시간메모리
528245Leo121Traffic (IOI10_traffic)C++14
100 / 100
977 ms161472 KiB
#include "traffic.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 pesosub[lim]; int padre[lim]; ll dfs(int u){ pesosub[u] = (ll) pesos[u]; for(int v : graph[u]){ if(!visitado[v]){ padre[v] = u; visitado[v] = 1; pesosub[u] += dfs(v); } } return pesosub[u]; } 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; 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(minimo >= aux){ minimo = aux; res = i; } } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...