Submission #408373

# Submission time Handle Problem Language Result Execution time Memory
408373 2021-05-19T07:14:49 Z muhammad_hokimiyon Stations (IOI20_stations) C++14
Compilation error
0 ms 0 KB
#include "stations.h"
#include <vector>
#include<bits/stdc++.h>

using namespace std;

const int N = 1e3 + 7;

int d[N];
vector<int> v[N];

void dfs(int x, int p)
{
    for(auto y : v[x]){
        if(y == p)continue;
        d[y] = d[x] + 1;
        dfs(y, x);
    }
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	std::vector<int> labels(n);
	for(int i = 0; i < n - 1; i++){
        int x = u[i], y = v[i];
        v[x].push_back(y);
        v[y].push_back(x);
	}
	int st = 0;
	for(int i = 1; i < n; i++){
        if((int)v[i].size() < (int)v[st].size()){
            st = i;
        }
	}
	dfs(st, st);
	for(int i = 0; i < n; i++){
        labels[i] = d[i];
	}
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    for(auto x : c){
        if(s < t && x < s)return x;
        if(s > t && x > s)return x;
    }
    assert(0);
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:25:14: error: request for member 'push_back' in 'v.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   25 |         v[x].push_back(y);
      |              ^~~~~~~~~
stations.cpp:26:14: error: request for member 'push_back' in 'v.std::vector<int>::operator[](((std::vector<int>::size_type)y))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   26 |         v[y].push_back(x);
      |              ^~~~~~~~~
stations.cpp:30:22: error: request for member 'size' in 'v.std::vector<int>::operator[](((std::vector<int>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   30 |         if((int)v[i].size() < (int)v[st].size()){
      |                      ^~~~
stations.cpp:30:42: error: request for member 'size' in 'v.std::vector<int>::operator[](((std::vector<int>::size_type)st))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   30 |         if((int)v[i].size() < (int)v[st].size()){
      |                                          ^~~~