답안 #361933

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
361933 2021-02-01T09:45:19 Z valerikk 기지국 (IOI20_stations) C++17
컴파일 오류
0 ms 0 KB
#include <stations.h>
#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:12:5: error: 'function' was not declared in this scope; did you mean 'union'?
   12 |     function<void(int, int)> dfs = [&](int u, int p) {
      |     ^~~~~~~~
      |     union
stations.cpp:12:27: error: expression list treated as compound expression in functional cast [-fpermissive]
   12 |     function<void(int, int)> dfs = [&](int u, int p) {
      |                           ^
stations.cpp:12:14: error: expected primary-expression before 'void'
   12 |     function<void(int, int)> dfs = [&](int u, int p) {
      |              ^~~~
stations.cpp:20:7: warning: left operand of comma operator has no effect [-Wunused-value]
   20 |     }(0, -1);
      |       ^
stations.cpp:11:9: warning: unused variable 't' [-Wunused-variable]
   11 |     int t = 0;
      |         ^
stations.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
   23 | }
      | ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:29:8: error: expected primary-expression before ';' token
   29 |     std;:vector<int> in_c, out_c;
      |        ^
stations.cpp:29:9: error: expected primary-expression before ':' token
   29 |     std;:vector<int> in_c, out_c;
      |         ^
stations.cpp:31:9: error: 'in_c' was not declared in this scope; did you mean 'in_t'?
   31 |         in_c.push_back(u / 1000);
      |         ^~~~
      |         in_t
stations.cpp:32:9: error: 'out_c' was not declared in this scope; did you mean 'out_t'?
   32 |         out_c.push_back(u % 1000);
      |         ^~~~~
      |         out_t
stations.cpp:36:13: error: 'in_c' was not declared in this scope; did you mean 'in_t'?
   36 |         if (in_c[i] <= in_s && out_c[i] >= out_s) {
      |             ^~~~
      |             in_t
stations.cpp:36:32: error: 'out_c' was not declared in this scope; did you mean 'out_t'?
   36 |         if (in_c[i] <= in_s && out_c[i] >= out_s) {
      |                                ^~~~~
      |                                out_t