제출 #312149

#제출 시각아이디문제언어결과실행 시간메모리
312149AmineTrabelsiTraffic (IOI10_traffic)C++17
25 / 100
5047 ms29816 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; #define pb push_back #define mp make_pair #define f first #define s second #define sz(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() // Hi const int M = 1e6; vector<int> gr[M]; int *people; pair<ll,ll> dfs(int i,int par){ pair<ll,ll> res = {-1,-1}; for(auto u:gr[i]){ if(u!= par){ pair<ll,ll> p = dfs(u,i); if(res.f == -1){ res.f = p.f+people[u]; }else res.s = p.f+people[u]; } } return res; } ll LocateCentre(int n,int p[],int ff[],int d[]){ for(int i=0;i<n-1;i++){ gr[ff[i]].pb(d[i]); gr[d[i]].pb(ff[i]); } people = p; ll res = 1e18; int city = 0; for(int i=0;i<n;i++){ pair<ll,ll> x = dfs(i,i); if(max(x.f,x.s) < res){ res = max(x.f,x.s); city = i; } } return city; } /* int main(){ int p[5] = {10,10,10,20,20},s[4] = {0,1,2,3},d[4] = {1,2,3,4}; cout<<LocateCentre(5,p,s,d)<<'\n'; return 0; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...