Submission #1014567

#TimeUsernameProblemLanguageResultExecution timeMemory
1014567lalig777Traffic (IOI10_traffic)C++14
100 / 100
618 ms186448 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long int ll; const int MAXN=1e5+5; vector<vector<int>> listaAdy; vector<ll>dp; int n; ll res=1e18; int answer=-1; ll total=0; void dfs1(int nodo, int padre, int P[]){ ll maxi=0; for(int v: listaAdy[nodo]){ if (v==padre) continue; dfs1(v, nodo, P); dp[nodo]+=dp[v]; maxi=max(maxi, dp[v]); }dp[nodo]+=P[nodo]; maxi=max(maxi, total-dp[nodo]); if (maxi<res){ res=maxi; answer=nodo; }return; } int LocateCentre(int N, int P[], int S[], int D[]) { listaAdy.clear(); listaAdy.resize(N); dp.clear(); dp.resize(N); for (int i=0; i<N; i++) total+=P[i]; for (int i=0; i<N-1; i++){ listaAdy[S[i]].push_back(D[i]); listaAdy[D[i]].push_back(S[i]); }dfs1(0,0,P); return answer; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...