Submission #598328

#TimeUsernameProblemLanguageResultExecution timeMemory
598328acatmeowmeowTraffic (IOI10_traffic)C++11
100 / 100
1262 ms198220 KiB
#include "traffic.h" #include <bits/stdc++.h> using namespace std; void dfs(int u, int e, vector<vector<int>>&adj, vector<int>&dp, int P[]) { dp[u] += P[u]; for (auto&v : adj[u]) { if (v == e) continue; dfs(v, u, adj, dp, P); dp[u] += dp[v]; } } void reroot(int u, int e, vector<vector<int>>&adj, vector<int>&dp, int P[], int&mn, int&ans) { int cur = 0; for (auto&v : adj[u]) cur = max(cur, dp[v]); if (cur < mn) mn = cur, ans = u; for (auto&v : adj[u]) { if (v == e) continue; dp[u] -= dp[v], dp[v] += dp[u]; reroot(v, u, adj, dp, P, mn, ans); dp[v] -= dp[u], dp[u] += dp[v]; } } int LocateCentre(int N, int P[], int S[], int D[]) { // build adjacency array vector<vector<int>> adj(N + 5); for (int i = 0; i < N - 1; i++) adj[S[i]].push_back(D[i]), adj[D[i]].push_back(S[i]); // dp vector<int> dp(N + 5); dfs(0, -1, adj, dp, P); // solve for all roots int mn = 1e18, ans = -1; reroot(0, -1, adj, dp, P, mn, ans); return ans; }

Compilation message (stderr)

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:36:11: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   36 |  int mn = 1e18, ans = -1;
      |           ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...