제출 #384997

#제출 시각아이디문제언어결과실행 시간메모리
384997ritul_kr_singhTraffic (IOI10_traffic)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "traffic.h" using namespace std; const int MAXN = 1e6; vector<vector<int>> g; int sub[MAXN], sum = 0, curr = 0, ans = 1e18; void dfs0(int u, int par){ for(int v : g[u]) if(v != par){ sub[u] += dfs0(v, u); curr = max(curr, sub[v]); } return sub[u]; } void dfs1(int u, int par){ ans = min(ans, curr); for(int v : g[u]){ if(v==par) continue; int prev = curr; curr = max(curr, sum - sub[v]); dfs1(v, u); curr = prev; } } int LocateCentre(int n, int pop[], int S[], int D[]){ for(int i=0; i<n; ++i) sum += (sub[i] = pop[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]); } dfs0(0, 0); dfs1(0, 0); return ans; }

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

traffic.cpp:7:41: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
    7 | int sub[MAXN], sum = 0, curr = 0, ans = 1e18;
      |                                         ^~~~
traffic.cpp: In function 'void dfs0(int, int)':
traffic.cpp:11:18: error: void value not ignored as it ought to be
   11 |    sub[u] += dfs0(v, u);
      |              ~~~~^~~~~~
traffic.cpp:14:14: error: return-statement with a value, in function returning 'void' [-fpermissive]
   14 |  return sub[u];
      |              ^