답안 #309354

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309354 2020-10-03T09:45:53 Z xt0r3 기지국 (IOI20_stations) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;

int timer;
vector<bool> f;
vector<int> l, d;
vector<vector<int> > g;

void dfs(int id, bool flag = 1){
    d[id] = timer++;
    f[id] = flag;
    for(int v : g[id]) if(d[v] == -1) dfs(v, !flag);
    l[id] = timer++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v){
    f.resize(n);
    l.assign(n, -1);
    d.assign(n, -1);
    g.assign(n, {});
    for(int i = 0; i < n - 1; i++){
        g[u[i]].push_back(v[i]);
        g[v[i]].push_back(u[i]);
    }
    timer = 0;
    dfs(0);
    vector<int> ret(n);
    for(int i = 0; i < n; i++){
        ret[i] = (f[i] ? d[i] / 2 : l[i] / 2);
    }
}

int find_next_station(int s, int t, vector<int> c){
    if(s < c[0]){
        //c has leaving times
        if(s < c.front() || s > c.back()) return c.back();
        return c[(int)(lower_bound(c.begin(), c.end(), t)];
    }
    else{
        //c has discovery times
        if(s < c.front() || s > c.back()) return c.front();
        return c[(int)(upper_bound(c.begin(), c.end(), t)) - 1];
    }
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:31:1: warning: no return statement in function returning non-void [-Wreturn-type]
   31 | }
      | ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:37:58: error: expected ')' before ']' token
   37 |         return c[(int)(lower_bound(c.begin(), c.end(), t)];
      |                       ~                                  ^
      |                                                          )
stations.cpp:37:58: error: invalid cast from type '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to type 'int'
stations.cpp:37:59: error: expected ']' before ';' token
   37 |         return c[(int)(lower_bound(c.begin(), c.end(), t)];
      |                                                           ^
      |                                                           ]
stations.cpp:42:58: error: invalid cast from type '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to type 'int'
   42 |         return c[(int)(upper_bound(c.begin(), c.end(), t)) - 1];
      |                                                          ^