Submission #231730

# Submission time Handle Problem Language Result Execution time Memory
231730 2020-05-14T14:48:16 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;
char v[1 + nmax * 2];
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 candidate.second;
}

Compilation message

traffic.cpp:9:15: error: conflicting declaration 'int v [1000001]'
 int v[1 + nmax], sum[1 + nmax];
               ^
traffic.cpp:8:6: note: previous declaration as 'char v [2000001]'
 char v[1 + nmax * 2];
      ^
traffic.cpp: In function 'void dfs(int, int)':
traffic.cpp:16: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:27: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 LocateCentre(int, std::vector<int>, std::vector<int>, std::vector<int>)':
traffic.cpp:50:10: error: 'candidate' was not declared in this scope
   return candidate.second;
          ^~~~~~~~~
traffic.cpp:50:10: note: suggested alternative: 'random_data'
   return candidate.second;
          ^~~~~~~~~
          random_data