Submission #528014

#TimeUsernameProblemLanguageResultExecution timeMemory
528014HydrolyzedTraffic (IOI10_traffic)C++14
50 / 100
204 ms262148 KiB
/* * AUTHOR : Hydrolyzed~ * SCHOOL : RYW * TASK : IOI10_traffic * ALGO : Dynamic Programming on Tree * DATE : 19 Feb 2022 * */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #ifndef _DEBUG // @==== Libary ====@ // #include "traffic.h" // @================@ // #endif using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ; // @=== Debugger ===@ // #ifdef _DEBUG #include "debug.hpp" #else #define dbg(...) 0 #endif // @================@ // using ll = long long; const int MxN = 10000100; int dp[MxN], pp[MxN], res = 1e9 + 1000, res_id; vector<int> adj[MxN]; void dfs(int u, int p){ dp[u] = pp[u]; for(auto x: adj[u]){ if(x == p){ continue; } dfs(x, u); dp[u] += dp[x]; } } void dfs2(int u, int p, int last){ int maxx = last; for(auto x: adj[u]){ if(x == p){ continue; } dfs2(x, u, last + dp[u] - dp[x]); maxx = max(maxx, dp[x]); } if(res > maxx){ res = maxx; res_id = u; } } int LocateCentre(int n, int p[], int s[], int d[]){ for(int i=0; i<n-1; ++i){ adj[s[i]].push_back(d[i]); adj[d[i]].push_back(s[i]); } for(int i=0; i<n; ++i){ pp[i] = p[i]; } dfs(0, 0); dfs2(0, 0, 0); return res_id; } #ifdef _DEBUG static int N,P[1000000],S[1000000],D[1000000]; int main(){ int i; scanf("%d",&N); for (i=0;i<N;i++) scanf("%d",&P[i]); for (i=0;i<N-1;i++) scanf("%d%d",&S[i],&D[i]); int r = LocateCentre(N,P,S,D); printf("%d\n",r); return 0; } #endif /* inline void solution(){ return ; } signed main(){ cin.tie(nullptr)->ios::sync_with_stdio(false); int q = 1; // cin >> q; while(q--){ solution(); cout << "\n"; } return 0; } */ // https://github.com/MasterIceZ/archive/tree/main/cpp-template
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...