Submission #361935

# Submission time Handle Problem Language Result Execution time Memory
361935 2021-02-01T09:46:18 Z valerikk Stations (IOI20_stations) C++17
Compilation error
0 ms 0 KB
#include <stations.h>
#include <functional>
#include <vector>

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
    std::vector<std::vector<int>> e(n);
    for (int i = 0; i < n - 1; i++) {
        e[u[i]].push_back(v[i]);
        e[v[i]].push_back(u[i]);
    }
    std::vector<int> in(n), out(n);
    int t = 0;
    std::function<void(int, int)> dfs = [&](int u, int p) {
        in[u] = t++;
        for (int v: e[u]) {
            if (v != p) {
                dfs(v, u);
            }
        }
        out[u] = min(n - 1, t);
    }(0, -1);
    std::vector<int> res(n);
    for (int i = 0; i < n; i++) res[i] = in[i] * 1000 + out[i];
}

int find_next_station(int s, int t, std::vector<int> c) {
    int in_s = s / 1000, out_s = s % 1000;
    if (in_s == 0) out_s++;
    int in_t = t / 1000, out_t = t % 1000;
    std;:vector<int> in_c, out_c;
    for (int u: c) {
        in_c.push_back(u / 1000);
        out_c.push_back(u % 1000);
    }
    int p = -1;
    for (size_t i = 0; i < c.size(); i++) {
        if (in_c[i] <= in_s && out_c[i] >= out_s) {
            p = c[i]; 
        } else {
            if (in_c[i] <= in_t && out_c[i] >= out_t) {
                return c[i];
            }
        }
    }
    return p;
}

Compilation message

stations.cpp: In lambda function:
stations.cpp:20:18: error: 'min' was not declared in this scope; did you mean 'std::min'?
   20 |         out[u] = min(n - 1, t);
      |                  ^~~
      |                  std::min
In file included from /usr/include/c++/9/functional:65,
                 from stations.cpp:2:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: 'std::min' declared here
 3450 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:21:6: error: conversion from 'void' to non-scalar type 'std::function<void(int, int)>' requested
   13 |     std::function<void(int, int)> dfs = [&](int u, int p) {
      |                                         ~~~~~~~~~~~~~~~~~~~
   14 |         in[u] = t++;
      |         ~~~~~~~~~~~~
   15 |         for (int v: e[u]) {
      |         ~~~~~~~~~~~~~~~~~~~
   16 |             if (v != p) {
      |             ~~~~~~~~~~~~~
   17 |                 dfs(v, u);
      |                 ~~~~~~~~~~
   18 |             }
      |             ~
   19 |         }
      |         ~
   20 |         out[u] = min(n - 1, t);
      |         ~~~~~~~~~~~~~~~~~~~~~~~
   21 |     }(0, -1);
      |     ~^~~~~~~
stations.cpp:24:1: warning: no return statement in function returning non-void [-Wreturn-type]
   24 | }
      | ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:30:8: error: expected primary-expression before ';' token
   30 |     std;:vector<int> in_c, out_c;
      |        ^
stations.cpp:30:9: error: expected primary-expression before ':' token
   30 |     std;:vector<int> in_c, out_c;
      |         ^
stations.cpp:32:9: error: 'in_c' was not declared in this scope; did you mean 'in_t'?
   32 |         in_c.push_back(u / 1000);
      |         ^~~~
      |         in_t
stations.cpp:33:9: error: 'out_c' was not declared in this scope; did you mean 'out_t'?
   33 |         out_c.push_back(u % 1000);
      |         ^~~~~
      |         out_t
stations.cpp:37:13: error: 'in_c' was not declared in this scope; did you mean 'in_t'?
   37 |         if (in_c[i] <= in_s && out_c[i] >= out_s) {
      |             ^~~~
      |             in_t
stations.cpp:37:32: error: 'out_c' was not declared in this scope; did you mean 'out_t'?
   37 |         if (in_c[i] <= in_s && out_c[i] >= out_s) {
      |                                ^~~~~
      |                                out_t