Submission #899537

#TimeUsernameProblemLanguageResultExecution timeMemory
899537IwanttobreakfreeTraffic (IOI10_traffic)C++14
0 / 100
1 ms4440 KiB
#include <bits/stdc++.h> using namespace std; int best_ans = 2e9+2, nodo_final = -1; int total_residents; int dfs(int nodoActual, vector<vector<int>>& lista, int par, int P[]) { // ans cuenta los residentes del subarbol // maxi se quedara con la maxima afluencia de cada vecino int total_subtree_residents = P[nodoActual], maxi = 0; for (int vecino: lista[nodoActual]) { if (vecino == par) continue; int subtree_resi = dfs(vecino, lista, nodoActual, P); total_subtree_residents += subtree_resi; maxi = max(maxi, subtree_resi); } maxi = max(maxi, total_residents-total_subtree_residents); // Restamos el total menos el subtree y sabremos cuantos llegan // por el padre if (maxi < best_ans) { maxi = best_ans; nodo_final = nodoActual; } return total_subtree_residents; } int LocateCentre (int N, int P[], int S[], int D[]) { vector<vector<int>> g(N, vector<int>()); vector<int> subtreeSz(N); for (int i = 0; i < N-1; ++i) { g[S[i]].push_back(D[i]); g[D[i]].push_back(S[i]); } total_residents = 0; for (int i = 0; i < N; ++i) total_residents += P[i]; dfs(0, g, 0, P); return nodo_final; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...