제출 #1211275

#제출 시각아이디문제언어결과실행 시간메모리
1211275SpyrosAliv통행료 (IOI18_highway)C++20
컴파일 에러
0 ms0 KiB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long

vector<vector<pair<int, int>>> tree;
vector<int> par, dep, edgeLab;
int n, a, b, maxD;

void prec(int node, int p = 0, int d = 0) {
    par[node] = p;
    dep[node] = d;
    maxD = max(maxD, d);
    for (auto [next, lab]: tree[node]) {
        if (next == p) continue;
        edgeLab[next] = lab;
        prec(next, node, d+1);
    }
}

int find_second(int root) {
    par.assign(n, 0);
    dep.assign(n, 0);
    edgeLab.assign(n, 0);
    maxD = 0;
    prec(root, 0);
    vector<int> q;
    q.assign(n-1, 0);
    ll init = ask(q);
    int lo = 1, hi = maxD;
    int secDep = 0;
    while (lo <= hi) {
        int mid = (lo + hi) / 2;
        fill(q.begin(), q.end(), 0);
        for (int i = 0; i < n; i++) {
            if (dep[i] >= mid) {
                q[edgeLab[i]] = 1;
            }
        }
        ll ret = ask(q);
        if (ret != init) {
            secDep = mid;
            lo = mid+1;
        }
        else hi = mid-1;
    }
    vector<int> cands;
    for (int i = 0; i < n; i++) {
        if (dep[i] == secDep) cands.push_back(i);
    }
    int sz = cands.size();
    lo = 0, hi = sz-1;
    int fin = 0;
    while (lo <= hi) {
        int mid = (lo + hi) / 2;
        fill(q.begin(), q.end(), 0);
        for (int i = 0; i <= mid; i++) {
            q[edgeLab[cands[i]]] = 1;
        }
        ll ret = ask(q);
        if (ret != init) {
            fin = mid;
            hi = mid-1;
        }
        else lo = mid+1;
    }
    return cands[fin];
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
    n = N;
    tree.clear();
    tree.resize(n);
    for (int i = 0; i < n-1; i++) {
        tree[U[i]].push_back(V[i]);
        tree[V[i]].push_back(U[i]);
    }
    a = A;
    b = B;
    answer(0, find_second(0));
}

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

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:75:29: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   75 |         tree[U[i]].push_back(V[i]);
      |         ~~~~~~~~~~~~~~~~~~~~^~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from highway.h:3,
                 from highway.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
highway.cpp:76:29: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   76 |         tree[V[i]].push_back(U[i]);
      |         ~~~~~~~~~~~~~~~~~~~~^~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from highway.h:3,
                 from highway.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~