Submission #958321

#TimeUsernameProblemLanguageResultExecution timeMemory
958321vjudge1Traffic (IOI10_traffic)C++17
0 / 100
11 ms31320 KiB
#include "traffic.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define pii pair<int, int> #define pll pair<ll, ll> const int N = 1000069; const ll mod = 1e9 + 7; int tc, ans; ll sub[N], tot, dp[N]; vector<int> al[N]; void dfs(int x, int p, int P[]) { sub[x] += (ll)P[x]; for(auto z : al[x]) { if(z == p) continue; dfs(z, x, P); sub[x] += sub[z]; } } void dfs2(int x, int p) { for(auto z : al[x]) { if(z == p) continue; dfs2(z, x); dp[x] = max(dp[x], sub[z]); } dp[x] = max(dp[x], tot - sub[x]); if(dp[x] < dp[ans]) ans = x; } int LocateCentre(int n, int P[], int S[], int D[]) { int i, j; ans = 0; for(i = 0; i < n; i++) tot += (ll)P[i]; for(i = 0; i < n-1; i++) { al[S[i]].push_back(D[i]); al[D[i]].push_back(S[i]); } dfs(0, -1, P); dfs2(0, -1); return ans; } // int main() // { // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // int i, j; // int n; // cin >> n; // tot = n; // for(i = 1; i < n; i++) // { // int u, v; // cin >> u >> v; // al[u].push_back(v); // al[v].push_back(u); // } // dfs(1, 1); // for(i = 1; i <= n; i++) cout << i << " : " << sub[i] << '\n'; // }

Compilation message (stderr)

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:44:12: warning: unused variable 'j' [-Wunused-variable]
   44 |     int i, j;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...