답안 #361934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
361934 2021-02-01T09:45:57 Z valerikk 기지국 (IOI20_stations) C++17
컴파일 오류
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;
    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 function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:13:5: error: 'function' was not declared in this scope; did you mean 'std::function'?
   13 |     function<void(int, int)> dfs = [&](int u, int p) {
      |     ^~~~~~~~
      |     std::function
In file included from /usr/include/c++/9/functional:59,
                 from stations.cpp:2:
/usr/include/c++/9/bits/std_function.h:128:11: note: 'std::function' declared here
  128 |     class function;
      |           ^~~~~~~~
stations.cpp:13:27: error: expression list treated as compound expression in functional cast [-fpermissive]
   13 |     function<void(int, int)> dfs = [&](int u, int p) {
      |                           ^
stations.cpp:13:14: error: expected primary-expression before 'void'
   13 |     function<void(int, int)> dfs = [&](int u, int p) {
      |              ^~~~
stations.cpp:21:7: warning: left operand of comma operator has no effect [-Wunused-value]
   21 |     }(0, -1);
      |       ^
stations.cpp:12:9: warning: unused variable 't' [-Wunused-variable]
   12 |     int t = 0;
      |         ^
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