Submission #487131

#TimeUsernameProblemLanguageResultExecution timeMemory
487131Spade1Traffic (IOI10_traffic)C++14
100 / 100
904 ms170680 KiB
#include <bits/stdc++.h> #include "traffic.h" #define ll long long #define pii pair<int, int> #define st first #define nd second #define pb push_back using namespace std; const int maxN = 1e6 + 10; vector<int> adj[maxN]; int prt[maxN], dis[maxN]; int dfs(int i, int p) { for (auto j : adj[i]) { if (j == p) continue; dis[i] += dfs(j, i); prt[j] = i; } return dis[i]; } int LocateCentre(int N, int P[], int S[], int D[]) { for (int i = 0; i < N - 1; ++i) { adj[S[i]].pb(D[i]); adj[D[i]].pb(S[i]); } for (int i = 0; i < N; ++i) { dis[i] = P[i]; } dfs(0, -1); int ans = 2e9, c; for (int i = 0; i < N; ++i) { int tmp = 0; for (auto j : adj[i]) { if (j == prt[i]) tmp = max(tmp, dis[0] - dis[i] ); else tmp = max(tmp, dis[j]); } if (tmp < ans) c = i, ans = tmp; } return c; }

Compilation message (stderr)

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:47:12: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |     return c;
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...