제출 #991112

#제출 시각아이디문제언어결과실행 시간메모리
991112borisAngelovTraffic (IOI10_traffic)C++17
100 / 100
821 ms198096 KiB
#include "traffic.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1000005; const long long inf = (1LL << 62); int n; int a[maxn]; vector<int> g[maxn]; long long subtreeSum[maxn]; long long down[maxn]; long long prv[maxn]; long long ans[maxn]; void dfsInit(int node, int par) { subtreeSum[node] = a[node]; down[node] = 0; for (int i = 0; i < g[node].size(); ++i) { if (g[node][i] != par) { dfsInit(g[node][i], node); subtreeSum[node] += subtreeSum[g[node][i]]; down[node] = max(down[node], subtreeSum[g[node][i]]); } } prv[node] = down[node]; } void dfsSolve(int node, int par) { ans[node] = down[node]; for (int i = 0; i < g[node].size(); ++i) { int to = g[node][i]; if (to != par) { subtreeSum[node] -= subtreeSum[to]; subtreeSum[to] += subtreeSum[node]; down[to] = max(down[to], subtreeSum[node]); dfsSolve(to, node); down[to] = prv[to]; subtreeSum[to] -= subtreeSum[node]; subtreeSum[node] += subtreeSum[to]; } } } int LocateCentre(int N, int pp[], int S[], int D[]) { n = N; for (int i = 1; i <= n; ++i) { a[i] = pp[i - 1]; } for (int i = 1; i <= n - 1; ++i) { int x = S[i - 1]; int y = D[i - 1]; ++x; ++y; g[x].push_back(y); g[y].push_back(x); } dfsInit(1, -1); dfsSolve(1, -1); long long big = inf; int node = -1; for (int i = 1; i <= n; ++i) { //cout << i << " :: " << ans[i] << endl; if (big > ans[i]) { big = ans[i]; node = i; } } //cout << big << endl; return node - 1; }

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

traffic.cpp: In function 'void dfsInit(int, int)':
traffic.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 0; i < g[node].size(); ++i)
      |                     ~~^~~~~~~~~~~~~~~~
traffic.cpp: In function 'void dfsSolve(int, int)':
traffic.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i = 0; i < g[node].size(); ++i)
      |                     ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...