제출 #393367

#제출 시각아이디문제언어결과실행 시간메모리
393367huukhangTraffic (IOI10_traffic)C++11
0 / 100
1 ms332 KiB
// - Only when necessary :d // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") #include "traffic.h" #include <bits/stdc++.h> using namespace std; const int inf = 2e9; int sum = 0; int a[1000005]; vector<vector<int>> g; int sz[1000005], congest[1000005]; void dfs(int s, int p) { 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] - a[s]); sz[s] += a[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); for (int i = 0; i < n - 1; ++i) { g[s[i]].push_back(d[i]); g[d[i]].push_back(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; }

컴파일 시 표준 에러 (stderr) 메시지

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