Submission #393356

#TimeUsernameProblemLanguageResultExecution timeMemory
393356huukhangTraffic (IOI10_traffic)C++11
0 / 100
1 ms308 KiB
// - Only when necessary :d // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") #include "traffic.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fileopen(a, b) freopen(((string)a + ".inp").c_str(), "r", stdin); freopen(((string)b + ".out").c_str(), "w", stdout); #define ll long long // #define int long long #define fi first #define se second #define pb push_back typedef pair<int, int> pii; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const ll mod = 1e9 + 7; const ll inf = 1e9 + 7; const double eps = 1e-9; int sum = 0; int a[1000005]; vector<vector<int>> g; int sz[1000005], congest[1000005]; void dfs(int s, int p) { sz[s] = a[s]; for (auto v : g[s]) { if (v != p) { dfs(v, s); sz[s] += sz[v]; congest[s] = max(congest[s], congest[v]); } } congest[s] = max(congest[s], sum - sz[s]); } int LocateCentre(int n, int p[], int s[], int d[]) { for (int i = 0; i < n; ++i) a[i] = p[i]; g.resize(n + 1); for (int i = 0; i < n - 1; ++i) { g[s[i]].pb(d[i]); g[d[i]].pb(s[i]); } for (int i = 0; i < n; ++i) sum += a[i]; dfs(0, -1); int mn = inf, ans; for (int i = 0; i < n; ++i) { if (mn > congest[i]) { mn = congest[i]; ans = i; } } return ans; }

Compilation message (stderr)

traffic.cpp: In function 'int LocateCentre(int, int*, int*, int*)':
traffic.cpp:66:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |  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...