제출 #463511

#제출 시각아이디문제언어결과실행 시간메모리
463511fuad27Traffic (IOI10_traffic)C++14
100 / 100
1110 ms149068 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define vii vector<pair<int, int>> #define vi vector<int> #define vl vector<long long> #define vll vector<pair<long long, long long>> #define mp make_pair #define pb push_back #define rep(i, a, b) for(int i = a;i<=b;i++) #define f first #define s second #define FIO ios_base::sync_with_stdio(0);cin.tie(0); #define start int tt;cin>>tt;rep(testcase, 1, tt) #define print(k) cout<<"Case #"<<testcase<<": "<<k<<"\n"; #define endl "\n" #define DEBUG(k) cerr<<k<<"\n"; vi adj[1000010]; int n, ans, a[1000010]; ll res = 1e18, sum = 0; ll solve(int x, int pa) { ll mv = 0, s = 0; for (int i = 0; i < (int) adj[x].size(); i++) { if (adj[x][i] == pa) continue; ll t = solve(adj[x][i], x); s += t; mv = max(mv, t); } s += a[x]; mv = max(mv, sum - s); if (res > mv) { res = mv; ans = x; } return s; } int LocateCentre(int N, int pp[], int S[], int D[]) { n = N; for (int i = 0; i < n; i++) { a[i] = pp[i]; sum += a[i]; } for (int i = 0; i < n - 1; i++) { adj[S[i]].push_back(D[i]); adj[D[i]].push_back(S[i]); } solve(0, -1); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...