답안 #320154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
320154 2020-11-07T19:03:26 Z nickmet2004 기지국 (IOI20_stations) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "stations.h"
using namespace std;
const int N = 1005;
vector<int> adj[N];
int dtime;
void dfs(int u , vector<int> &R ,int p = -1){
    R[u] =1000 * dtime; dtime++;
    for(int v : adj[u])if(v ^ p)dfs(v ,u);
    R[u] += dtime;
}
vector<int> label(int n , int k ,vector<int> u , vector<int> v){
    for(int i = 0; i < n; ++i) adj[i].clear();
    for(int i = 0; i < n-1; ++i) adj[u[i]].emplace_back(v[i]) , adj[v[i]].emplace_back(u[i]);
    vector<int> R(n);
    dtime =0;
    dfs(0 , R);
    return R;
}
int find_next_station(int s , int t , vector<int> c){
    reverse(c.begin() , c.end());
    for(int x : c){
        int in = x / 1000 , out = x % 1000;
        if(in <= t && t <= out) return x;
    }
    return c.back();
}
/*
int main (){
    cin >> n;
    for(int i =1; i < n; ++i){
        int u , v; cin >> u>> v;
        adj[u].emplace_back(v); adj[v].emplace_back(u);
    }
    vector<int> k = label(n , 1 , {3} , {3});
    cout << find_next_station(1 , 3 , {3 , 2 ,0}) << endl;
}
*/
//int main (){}

Compilation message

stations.cpp: In function 'void dfs(int, std::vector<int>&, int)':
stations.cpp:9:40: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'int'
    9 |     for(int v : adj[u])if(v ^ p)dfs(v ,u);
      |                                        ^
stations.cpp:7:31: note: in passing argument 2 of 'void dfs(int, std::vector<int>&, int)'
    7 | void dfs(int u , vector<int> &R ,int p = -1){
      |                  ~~~~~~~~~~~~~^