Submission #385202

#TimeUsernameProblemLanguageResultExecution timeMemory
385202vishesh312Traffic (IOI10_traffic)C++17
0 / 100
1 ms364 KiB
#include "bits/stdc++.h" #include "traffic.h" using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; */ #define all(x) begin(x), end(x) #define sz(x) (int)x.size() using ll = long long; const int mod = 1e9+7; vector<int> sub, par; vector<vector<int>> adj; void dfs(int u, int p = -1) { par[u] = p; for (int v : adj[u]) { if (v != p) { dfs(v, u); } } for (int v : adj[u]) { if (v != p) { sub[u] += sub[v]; } } } int LocateCentre(int n, int v[], int U[], int V[]) { sub = vector<int>(v, v+n); par.resize(n); adj.resize(n); for (int i = 0; i < n; ++i) { adj[U[i]].push_back(V[i]); adj[V[i]].push_back(U[i]); } dfs(0); int ans, mx = 2e9+5; for (int i = 0; i < n; ++i) { int cur = sub[0] - sub[i]; for (int v : adj[i]) { if (v != par[i]) { cur = max(cur, sub[v]); } } if (cur < mx) { mx = cur; ans = i; } } return ans; }

Compilation message (stderr)

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