답안 #412511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412511 2021-05-27T03:04:42 Z two_sides 기지국 (IOI20_stations) C++17
컴파일 오류
0 ms 0 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

void dfs(int u, int p, bool d, int &cnt, const vector <vector <int>> &adj, vector <int> &label) {
    if (!d) label[u] = cnt++;
    for (int v : adj[u])
        if (v != p) dfs(v, u, !d, adj, label);
    if (d) label[u] = cnt++; 
}

vector <int> label(int n, int k, vector <int> u, vector <int> v) {
    vector <vector <int>> adj(n);
    vector <int> label(n);
    for (int i = 0; i + 1 < n; i++) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    int cnt = 0;
    dfs(0, -1, 0, cnt, adj, label);
    return label;
}

int find_next_station(int s, int t, vector <int> c) {
    if (s < c[0]) {
        int lo = s, hi = c.size() > 1 ? c[c.size() - 2] : s;
        if (lo <= t && t <= hi) {
            for (int u : c)
                if (u >= t) return u;
        }
        return c[c.size() - 1];
    } else {
        int hi = s, lo = c.size() > 1 ? c[1] : s;
        if (lo <= t && t <= hi) {
            for (int u : c)
                if (u <= t) return u;
        }
        return c[0];
    }
    return c[0];
}

Compilation message

stations.cpp: In function 'void dfs(int, int, bool, int&, const std::vector<std::vector<int> >&, std::vector<int>&)':
stations.cpp:9:35: error: invalid initialization of reference of type 'int&' from expression of type 'const std::vector<std::vector<int> >'
    9 |         if (v != p) dfs(v, u, !d, adj, label);
      |                                   ^~~
stations.cpp:6:37: note: in passing argument 4 of 'void dfs(int, int, bool, int&, const std::vector<std::vector<int> >&, std::vector<int>&)'
    6 | void dfs(int u, int p, bool d, int &cnt, const vector <vector <int>> &adj, vector <int> &label) {
      |                                ~~~~~^~~