제출 #1262627

#제출 시각아이디문제언어결과실행 시간메모리
1262627anteknne기지국 (IOI20_stations)C++20
컴파일 에러
0 ms0 KiB
#include "stations.h"
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define st first
#define nd second
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define debug false

const int MAXN = 1000 + 17;
vector<int> graf[MAXN];
int lev[MAXN];
int cnt = 0;
int nr[MAXN];

void DFS1 (int v, int o) {
    for (auto x : graf[v]) {
        if (x != o) {
            lev[x] = lev[v] + 1;
            DFS1(x, v);
        }
    }
}

void DFS2 (int v, int o) {
    if (lev[v] % 2 == 0) {
        nr[v] = cnt;
        cnt ++;
    }
    for (auto x : graf[v]) {
        if (x != o) {
            DFS2(x, v);
        }
    }
    if (lev[v] % 2 == 1) {
        nr[v] = cnt;
        cnt ++;
    }
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    vector<int> labels(n);

    for (int i = 0; i < n; i ++) {
        graf[i].clear();
    }
    for (int i = 0; i < n - 1 ; i ++) {
        graf[u[i].pb(v[i]);
        graf[v[i]].pb(u[i]);
    }
    cnt = 0;
    DFS1(0, 0);
    DFS2(0, 0);

    for (int i = 0; i < n; i ++) {
        labels[i] = nr[i];
    }

    return labels;
}

int find_next_station(int v, int u, vector<int> c) {
    sort(c.begin(), c.end());
    int r = int(c.size());
    if (v > c.back()) {
        for (int i = 1; i < r - 1; i ++) {
            if (c[i] <= u && u < c[i + 1]) {
                return c[i];
            }
        }
        if (c[r - 1] <= u && u < v)  {
            return c[r - 1];
        }
        return c[0];
    }
    for (int i = 1; i < r - 1; i ++) {
        if (c[i - 1] < u && u <= c[i]) {
            return c[i];
        }
    }
    if (v < u && u <= c[0]) {
        return c[0];
    }
    return c[r - 1];
}

컴파일 시 표준 에러 (stderr) 메시지

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:12:12: error: request for member 'push_back' in 'u.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'}
   12 | #define pb push_back
      |            ^~~~~~~~~
stations.cpp:58:19: note: in expansion of macro 'pb'
   58 |         graf[u[i].pb(v[i]);
      |                   ^~
stations.cpp:58:27: error: expected ']' before ';' token
   58 |         graf[u[i].pb(v[i]);
      |                           ^
      |                           ]