Submission #231731

# Submission time Handle Problem Language Result Execution time Memory
231731 2020-05-14T14:48:53 Z AlexLuchianov Traffic (IOI10_traffic) C++14
Compilation error
0 ms 0 KB
#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, vector<int> p, vector<int> s, vector<int> d){
  for(int i = 0; i < n; 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;
}

Compilation message

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++){
                  ~~^~~~~~~~~~~~~~~~
/tmp/ccyF20Zn.o: In function `main':
grader.cpp:(.text.startup+0xb1): undefined reference to `LocateCentre(int, int*, int*, int*)'
collect2: error: ld returned 1 exit status