제출 #1359440

#제출 시각아이디문제언어결과실행 시간메모리
1359440opeleklanos수천개의 섬 (IOI22_islands)C++20
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <vector>
#include <variant>
using namespace std;

vector<vector<int>> adj;

variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V){

    adj.assign(N, 0);
    for(int i = 0; i<M; i++){
        adj[U[i]].push_back(V[i]);
    }


    int curr = 0;
    while(adj[curr].size() == 1) curr = adj[curr][0];

    if(adj[curr].size() > 1) return (bool)1;
    else return (bool)0;
}

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

islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:10:15: error: no matching function for call to 'std::vector<std::vector<int> >::assign(int&, int)'
   10 |     adj.assign(N, 0);
      |     ~~~~~~~~~~^~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from islands.cpp:2:
/usr/include/c++/13/bits/stl_vector.h:828:9: note: candidate: 'template<class _InputIterator, class> constexpr void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]'
  828 |         assign(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:828:9: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/13/bits/stl_construct.h:61,
                 from /usr/include/c++/13/bits/char_traits.h:57,
                 from /usr/include/c++/13/ios:42,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from islands.cpp:1:
/usr/include/c++/13/bits/stl_iterator_base_types.h: In substitution of 'template<class _InIter> using std::_RequireInputIter = std::__enable_if_t<std::is_convertible<typename std::iterator_traits<_Iterator>::iterator_category, std::input_iterator_tag>::value> [with _InIter = int]':
/usr/include/c++/13/bits/stl_vector.h:825:9:   required from here
/usr/include/c++/13/bits/stl_iterator_base_types.h:250:11: error: no type named 'iterator_category' in 'struct std::iterator_traits<int>'
  250 |     using _RequireInputIter =
      |           ^~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:808:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; size_type = long unsigned int; value_type = std::vector<int>]'
  808 |       assign(size_type __n, const value_type& __val)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:808:47: note:   no known conversion for argument 2 from 'int' to 'const std::vector<std::vector<int> >::value_type&' {aka 'const std::vector<int>&'}
  808 |       assign(size_type __n, const value_type& __val)
      |                             ~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/13/bits/stl_vector.h:855:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]'
  855 |       assign(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:855:7: note:   candidate expects 1 argument, 2 provided