Submission #308625

# Submission time Handle Problem Language Result Execution time Memory
308625 2020-10-01T15:18:23 Z szekelymilan Stations (IOI20_stations) C++14
Compilation error
0 ms 0 KB
#include "stations.h"
#include <iostream>
#include <vector>

const int P = 2000;

std::vector<std::vector<int>> G;
std::vector<int> labels;
int time;

void DFS(int node = 0) {
  labels[node] = (time++) * P;

  for (int v : G[node])
    if (labels[v] == -1)
      DFS(v);
  
  labels[node] += time++;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
  G.assign(n, std::vector<int>());
  labels.assign(n, -1);
  time = 0;

  for (int i = 0; i < n - 1; i++) {
    G[u[i]].push_back(v[i]);
    G[v[i]].push_back(u[i]);
  }

  DFS();

  return labels;
}

inline bool inside(int a, int b) {
  return a / P <= b / P && b % P <= a % P;
}

int find_next_station(int s, int t, std::vector<int> c) {
  int parent = -1;

  for (int node : c)
    if (inside(node, s))
      parent = node;
  
  for (int node : c)
    if (node != parent && inside(node, t))
      return node;
  
  return parent;
}

Compilation message

stations.cpp:9:5: error: 'int time' redeclared as different kind of entity
    9 | int time;
      |     ^~~~
In file included from /usr/include/pthread.h:24,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/gthr.h:148,
                 from /usr/include/c++/9/ext/atomicity.h:35,
                 from /usr/include/c++/9/bits/ios_base.h:39,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from stations.cpp:2:
/usr/include/time.h:192:15: note: previous declaration 'time_t time(time_t*)'
  192 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
stations.cpp: In function 'void DFS(int)':
stations.cpp:12:23: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) throw ()' {aka 'long int (*)(long int*)'} [-Wpointer-arith]
   12 |   labels[node] = (time++) * P;
      |                       ^~
stations.cpp:12:23: error: lvalue required as increment operand
stations.cpp:18:23: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) throw ()' {aka 'long int (*)(long int*)'} [-Wpointer-arith]
   18 |   labels[node] += time++;
      |                       ^~
stations.cpp:18:23: error: lvalue required as increment operand
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:24:8: error: assignment of function 'time_t time(time_t*)'
   24 |   time = 0;
      |   ~~~~~^~~