제출 #895178

#제출 시각아이디문제언어결과실행 시간메모리
895178IrateTraffic (IOI10_traffic)C++14
0 / 100
1 ms4444 KiB
#include<bits/stdc++.h> using namespace std; vector<vector<int>>G; vector<long long>sz, val, res; int n; long long sum = 0; void dfs(int node, int par){ sz[node] = val[node]; for(int &v : G[node]){ if(v != par){ dfs(v, node); sz[node] += sz[v]; } } long long sub_sum = 0; for(int &v : G[node]){ res[node] = max(res[node], sz[v]); sub_sum += sz[v]; } res[node] = max(res[node], sum - sub_sum); } int LocateCentre(int N, int P[], int S[], int D[]){ int n = N; G.resize(n); sz.resize(n); res.resize(n); val.resize(n); for(int i = 0;i < n;++i){ val[i] = P[i]; sum += P[i]; } for(int i = 0;i < n - 1;++i){ G[S[i]].push_back(D[i]); G[D[i]].push_back(S[i]); } dfs(0, 0); long long mn = 1e18, id = -1; for(int i = 0;i < n;++i){ if(res[i] < mn){ mn = res[i]; id = i; } } return id; } // int main(){ // ios_base::sync_with_stdio(0); // cin.tie(0); // int n; // cin >> n; // vector<int>P(n), S(n - 1), D(n - 1); // for(int i = 0;i < n;++i){ // cin >> P[i]; // } // for(int i = 0;i < n - 1;++i){ // cin >> S[i] >> D[i]; // } // cout << LocateCentre(n, P, S, D); // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...