Submission #309353

# Submission time Handle Problem Language Result Execution time Memory
309353 2020-10-03T09:45:27 Z xt0r3 Stations (IOI20_stations) C++14
Compilation error
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[id] ? d[id] / 2 : l[id] / 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:29:21: error: 'id' was not declared in this scope; did you mean 'i'?
   29 |         ret[i] = (f[id] ? d[id] / 2 : l[id] / 2);
      |                     ^~
      |                     i
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];
      |                                                          ^