Submission #410577

#TimeUsernameProblemLanguageResultExecution timeMemory
410577tht2005Traffic (IOI10_traffic)C++14
0 / 100
15 ms23756 KiB
#include <bits/stdc++.h> using namespace std; #define nmax 1000100 int n, sum, a[nmax], s[nmax], d[nmax]; vector <int> adj[nmax]; int val[nmax]; void dfs1(int u, int parent) { val[u] = 0; for(int v: adj[u]) { if(v != parent) { dfs1(v, u); val[u] += a[v] + val[v]; } } } int LocateCentre(int n, int a[], int s[], int d[]) { sum = 0; for(int i = 0; i < n; ++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]); } dfs1(0, 0); for(int i = 0; i < n; ++i) { val[i] = max(val[i], sum - a[i] - val[i]); } return min_element(val, val + n) - val; } /* int main() * { * ios::sync_with_stdio(false); cin.tie(NULL); * * cin >> n; * for(int i = 0; i < n; ++i) * cin >> a[i]; * for(int i = 0; i < n - 1; ++i) * cin >> s[i]; * for(int i = 0; i < n - 1; ++i) * cin >> d[i]; * cout << LocateCentre(n, a, 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...