제출 #594358

#제출 시각아이디문제언어결과실행 시간메모리
594358SlavicG통행료 (IOI18_highway)C++17
컴파일 에러
0 ms0 KiB
#include "highway.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define sz(a) (int)a.size()

void dfs(int u, int par, vector<vector<int>>& adj, vector<int>& p, vector<int>& depth) {
    p[u] = par;
    for(int v: adj[u]) {
        if(v == par) continue;
        depth[v] = depth[u] + 1;
        dfs(v, u, adj, p, depth);
    }
}
int find(int start, int n, vector<int> u, vector<int> v) {
    map<pair<int, int>, int> idx;
    vector<vector<int>> adj(n);
    vector<int> p(n, 0), depth(n, 0);

    int m = u.size();
    for(int i = 0; i < m; ++i) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
        idx[{u[i], v[i]}] = idx[{v[i], u[i]}] = i;
    }
    dfs(start, -1, adj, p, depth);
    int l = 1, r = n, dd = -1;
    vector<int> c(m, 1);
    ll init = ask(c);
    while(l <= r) {
        int mid = l + r >> 1;
        for(int j = 0; j < n; ++j) {
            if(j == start) continue;
            if(depth[j] >= mid) {
                c[idx[{j, p[j]}]] = 0;
            }
        }
        if(ask(c) < init) {
            dd = mid;
            l = mid + 1;
        } else r = mid - 1;
        c.assign(m, 1);
    }
    vector<int> nodes;
    for(int i = 0; i < n; ++i) {
        if(i == start) continue;
        if(depth[i] == dd) nodes.push_back(i);
    }
    assert(sz(nodes) > 0);

    l = 0, r = sz(nodes) - 1;
    int pp = -1;
    while(l <= r) {
        int mid = l + r >> 1;
        for(int i = 0; i <= mid; ++i) {
            assert(p[nodes[i]] != -1);
            c[idx[{nodes[i], p[nodes[i]]}]] = 0;
        }
        if(ask(c) < init) {
            pp = mid;
            r = mid - 1;
        } else l = mid + 1;
        c.assign(m, 1);
    }
    assert(pp != -1);
    return nodes[pp];
}
void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
    int s = find(0, n, u, v);
    int t = find(n - 1 n, u, v);
    answer(0, s);
}

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

highway.cpp: In function 'int find(int, int, std::vector<int>, std::vector<int>)':
highway.cpp:31:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |         int mid = l + r >> 1;
      |                   ~~^~~
highway.cpp:54:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   54 |         int mid = l + r >> 1;
      |                   ~~^~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:70:23: error: expected ')' before 'n'
   70 |     int t = find(n - 1 n, u, v);
      |                 ~     ^~
      |                       )
highway.cpp:70:31: error: no matching function for call to 'find(int, std::vector<int>&, std::vector<int>&)'
   70 |     int t = find(n - 1 n, u, v);
      |                               ^
highway.cpp:15:5: note: candidate: 'int find(int, int, std::vector<int>, std::vector<int>)'
   15 | int find(int start, int n, vector<int> u, vector<int> v) {
      |     ^~~~
highway.cpp:15:5: note:   candidate expects 4 arguments, 3 provided
In file included from /usr/include/c++/10/bits/locale_facets.h:48,
                 from /usr/include/c++/10/bits/basic_ios.h:37,
                 from /usr/include/c++/10/ios:44,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from highway.cpp:2:
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)'
  422 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note:   template argument deduction/substitution failed:
highway.cpp:70:31: note:   mismatched types 'std::istreambuf_iterator<_CharT>' and 'int'
   70 |     int t = find(n - 1 n, u, v);
      |                               ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from highway.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3894:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3894 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/10/bits/stl_algo.h:3894:5: note:   template argument deduction/substitution failed:
highway.cpp:70:31: note:   deduced conflicting types for parameter '_IIter' ('int' and 'std::vector<int>')
   70 |     int t = find(n - 1 n, u, v);
      |                               ^
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from highway.cpp:2:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:60:1: note:   template argument deduction/substitution failed:
highway.cpp:70:31: note:   candidate expects 4 arguments, 3 provided
   70 |     int t = find(n - 1 n, u, v);
      |                               ^
highway.cpp:70:9: warning: unused variable 't' [-Wunused-variable]
   70 |     int t = find(n - 1 n, u, v);
      |         ^