Submission #231737

#TimeUsernameProblemLanguageResultExecution timeMemory
231737AlexLuchianovTraffic (IOI10_traffic)C++14
100 / 100
1305 ms159204 KiB
#include "traffic.h" #include <vector> #include <iostream> using namespace std; int const nmax = 1000000; int v[1 + nmax], sum[1 + nmax]; int far[1 + nmax]; vector<int> g[1 + nmax]; void dfs(int node, int parent){ far[node] = parent; sum[node] = v[node]; for(int h = 0; h < g[node].size(); h++){ int to = g[node][h]; if(to != parent) { dfs(to, node); sum[node] += sum[to]; } } } int eval(int node){ int result = sum[1] - sum[node]; for(int h = 0; h < g[node].size(); h++){ int to = g[node][h]; if(to != far[node]) result = max(result, sum[to]); } return result; } int LocateCentre(int n, int *p, int *s, int *d){ for(int i = 0; i < n - 1; i++){ s[i]++; d[i]++; g[s[i]].push_back(d[i]); g[d[i]].push_back(s[i]); } for(int i = 1;i <= n; i++) v[i] = p[i - 1]; dfs(1, 0); pair<int,int> sol(eval(1), 1); for(int i = 2;i <= n; i++){ pair<int,int> candidate(eval(i), i); sol = min(sol, candidate); } return sol.second - 1; }

Compilation message (stderr)

traffic.cpp: In function 'void dfs(int, int)':
traffic.cpp:15:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int h = 0; h < g[node].size(); h++){
                  ~~^~~~~~~~~~~~~~~~
traffic.cpp: In function 'int eval(int)':
traffic.cpp:26:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int h = 0; h < g[node].size(); h++){
                  ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...