Submission #1057101

#TimeUsernameProblemLanguageResultExecution timeMemory
1057101MalixThousands Islands (IOI22_islands)C++17
Compilation error
0 ms0 KiB
#include "islands.h"

#include <variant>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;
typedef vector<ll> li;
typedef vector<li> lii;
 
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))
 
ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;

int n,m;
vector<pii> arr;
vi vis,p,ans,ind;

void bfs(int x){
  vis[x]=1;
  int s=arr[x].size();
  if(s==1){
    ans.PB(-1);
    return;
  }
  if(s==2){
    int k=0;
    if(vis[arr[x][k].F])k++;
    ans.PB(arr[x][k].S);
    bfs(arr[x][k].F);
    if(ans.back()==-1)return;
    ans.PB(arr[x][k].S);
    return;
  }
  int k=0;
  if(vis[arr[x][k].F])k++;
  int z=arr[x][k].S;
  int y=-1;
  for(auto u:arr[arr[x][k].F])if(u.F==x)y=u.S;
  k++;
  while(vis[arr[x][k].F])k++;
  int c=arr[x][k].S;
  int d=-1;
  for(auto u:arr[arr[x][k].F])if(u.F==x&&u.S!=y)d=u.S;
  ans.PB(z);ans.PB(y);ans.PB(c);ans.PB(d);ans.PB(y);ans.PB(z);ans.PB(d);ans.PB(c);
  return;
}

int dfs(int x){
  vis[x]=1;ind.PB(x);
  for(auto u:arr[x]){
    if(p[x]==u)continue;
    if(vis[u]){
      ind.PB(u);
      return u;
    }
    int k=dfs(u);
    if(k!=-1)return k;
  }
  ind.pop_back();
  return -1;
}

std::variant<bool, std::vector<int>> find_journey(
    int N, int M, std::vector<int> U, std::vector<int> V) {
  n=N;m=M;
  map<pi,int> mp,mp2;
  REP(i,0,m){
    mp[{U[i],V[i]}]=i;
    i++;
    mp2[{U[i],V[i]}]=i;
  }
  if(n==2){
    if(m<=2)return false;
    vi a;
    REP(i,0,m)if(U[i]==0)a.PB(i);
    int p=-1;
    REP(i,0,m)if(U[i]!=0)p=i;
    int k=a.size();
    if(k<2||p==-1)return false;
    ans.PB(a[0]);ans.PB(p);ans.PB(a[1]);ans.PB(a[0]);ans.PB(p);ans.PB(a[1]);
    return ans;
  }
  arr.resize(n);
  REP(i,0,m)arr[U[i]].PB({V[i],i});
if(U[0]==U[1]){
  vis.resize(n,0);
  p.resize(n,-1);
  vis[0]=1;int k=-1;
  ind.PB(0);
  for(auto u:arr[0]){
    p[u]=0;ind.PB(u.F);
    k=dfs(u);
    if(k!=-1)break;
    ind.pop_back();
  }
  if(k==-1)return false;
  int pos=0;
  vi a;
  while(ind[pos]!=k){
    a.PB(mp[{ind[pos],ind[pos+1]}]);
    ans.PB(mp[{ind[pos],ind[pos+1]}]);
    pos++;
  }
  vi tmp;
  int z=ind.size();
  REP(i,pos,z-1)tmp.PB(ind[i]);
  z=tmp.size();vi b,c;
  REP(i,0,z-1){
    b.PB(mp[{tmp[i],tmp[i+1]}]);
    ans.PB(mp[{tmp[i],tmp[i+1]}]);
  }
  REP(i,0,z-1){
    c.PB(mp2[{tmp[i],tmp[i+1]}]);
    ans.PB(mp2[{tmp[i],tmp[i+1]}]);
  }
  reverse(b.begin,b.end());
  reverse(c.begin,c.end());
  for(auto u:b)ans.PB(u);
  for(auto u:c)ans.PB(u);

  reverse(a.begin,a.end());
  for(auto u:a)ans.PB(u);
  return ans;
}
  if(arr[0].size()>=2){
    int x=arr[0][0].S;
    int y=-1;
    for(auto u:arr[arr[0][0].F])if(u.F==0)y=u.S;
    int c=arr[0][1].S;
    int d=-1;
    for(auto u:arr[arr[0][1].F])if(u.F==0)d=u.S;
    ans.PB(x);ans.PB(y);ans.PB(c);ans.PB(d);ans.PB(y);ans.PB(x);ans.PB(d);ans.PB(c);
    return ans;
  }
  if(arr[0].empty())return false;
  vis.resize(n,0);
  vis[0]=1;
  ans.PB(arr[0][0].S);
  bfs(arr[0][0].F);
  if(ans.back()==-1)return false;
  ans.PB(arr[0][0].S);
  return ans;
}

Compilation message (stderr)

islands.cpp: In function 'int dfs(int)':
islands.cpp:63:12: error: no match for 'operator==' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::pair<int, int>')
   63 |     if(p[x]==u)continue;
In file included from /usr/include/c++/10/utility:70,
                 from /usr/include/c++/10/variant:37,
                 from islands.h:1,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:466:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
  466 |     operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:466:5: note:   template argument deduction/substitution failed:
islands.cpp:63:14: note:   mismatched types 'const std::pair<_T1, _T2>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   63 |     if(p[x]==u)continue;
      |              ^
In file included from islands.h:1,
                 from islands.cpp:1:
/usr/include/c++/10/variant:1186:3: note: candidate: 'template<class ... _Types> constexpr bool std::operator==(const std::variant<_Types ...>&, const std::variant<_Types ...>&)'
 1186 |   _VARIANT_RELATION_FUNCTION_TEMPLATE(==, equal)
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/variant:1186:3: note:   template argument deduction/substitution failed:
islands.cpp:63:14: note:   mismatched types 'const std::variant<_Types ...>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   63 |     if(p[x]==u)continue;
      |              ^
In file included from islands.h:1,
                 from islands.cpp:1:
/usr/include/c++/10/variant:1193:18: note: candidate: 'constexpr bool std::operator==(std::monostate, std::monostate)'
 1193 |   constexpr bool operator==(monostate, monostate) noexcept { return true; }
      |                  ^~~~~~~~
/usr/include/c++/10/variant:1193:29: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'std::monostate'
 1193 |   constexpr bool operator==(monostate, monostate) noexcept { return true; }
      |                             ^~~~~~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:360:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)'
  360 |     operator==(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:360:5: note:   template argument deduction/substitution failed:
islands.cpp:63:14: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   63 |     if(p[x]==u)continue;
      |              ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:398:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)'
  398 |     operator==(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:398:5: note:   template argument deduction/substitution failed:
islands.cpp:63:14: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   63 |     if(p[x]==u)continue;
      |              ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1427:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)'
 1427 |     operator==(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1427:5: note:   template argument deduction/substitution failed:
islands.cpp:63:14: note:   mismatched types 'const std::move_iterator<_IteratorL>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   63 |     if(p[x]==u)continue;
      |              ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1495:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)'
 1495 |     operator==(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1495:5: note:   template argument deduction/substitution failed:
islands.cpp:63:14: note:   mismatched types 'const std::move_iterator<_IteratorL>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   63 |     if(p[x]==u)continue;
      |              ^
In file included from /usr/include/c++/10/vector:64,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/allocator.h:206:5: note: candidate: 'template<class _T1, class _T2> bool std::operator==(const std::allocator<_Tp1>&, const std::allocator<_T2>&)'
  206 |     operator==(const allocator<_T1>&, const allocator<_T2>&)
      |     ^~~~~~~~
/usr/include/c++/10/bits/allocator.h:206:5: note:   template argument deduction/substitution failed:
islands.cpp:63:14: note:   mismatched types 'const std::allocator<_Tp1>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   63 |     if(p[x]==u)continue;
      |              ^
In file included from /usr/include/c++/10/vector:67,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1892:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator==(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)'
 1892 |     operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1892:5: note:   template argument deduction/substitution failed:
islands.cpp:63:14: note:   mismatched types 'const std::vector<_Tp, _Alloc>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   63 |     if(p[x]==u)continue;
      |              ^
islands.cpp:64:11: error: no match for 'operator[]' (operand types are 'vi' {aka 'std::vector<int>'} and 'std::pair<int, int>')
   64 |     if(vis[u]){
      |           ^
In file included from /usr/include/c++/10/vector:67,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::const_reference = const int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
islands.cpp:65:15: error: no matching function for call to 'std::vector<int>::push_back(std::pair<int, int>&)'
   65 |       ind.PB(u);
      |               ^
In file included from /usr/include/c++/10/vector:67,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
islands.cpp:66:14: error: cannot convert 'std::pair<int, int>' to 'int' in return
   66 |       return u;
      |              ^
islands.cpp:68:15: error: cannot convert 'std::pair<int, int>' to 'int'
   68 |     int k=dfs(u);
      |               ^
      |               |
      |               std::pair<int, int>
islands.cpp:60:13: note:   initializing argument 1 of 'int dfs(int)'
   60 | int dfs(int x){
      |         ~~~~^
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:78:3: error: 'map' was not declared in this scope
   78 |   map<pi,int> mp,mp2;
      |   ^~~
islands.cpp:2:1: note: 'std::map' is defined in header '<map>'; did you forget to '#include <map>'?
    1 | #include "islands.h"
  +++ |+#include <map>
    2 | 
islands.cpp:78:9: error: expected primary-expression before ',' token
   78 |   map<pi,int> mp,mp2;
      |         ^
islands.cpp:78:10: error: expected primary-expression before 'int'
   78 |   map<pi,int> mp,mp2;
      |          ^~~
islands.cpp:80:5: error: 'mp' was not declared in this scope; did you mean 'p'?
   80 |     mp[{U[i],V[i]}]=i;
      |     ^~
      |     p
islands.cpp:82:5: error: 'mp2' was not declared in this scope
   82 |     mp2[{U[i],V[i]}]=i;
      |     ^~~
islands.cpp:103:6: error: no match for 'operator[]' (operand types are 'vi' {aka 'std::vector<int>'} and 'std::pair<int, int>')
  103 |     p[u]=0;ind.PB(u.F);
      |      ^
In file included from /usr/include/c++/10/vector:67,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::const_reference = const int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
islands.cpp:104:11: error: cannot convert 'std::pair<int, int>' to 'int'
  104 |     k=dfs(u);
      |           ^
      |           |
      |           std::pair<int, int>
islands.cpp:60:13: note:   initializing argument 1 of 'int dfs(int)'
   60 | int dfs(int x){
      |         ~~~~^
islands.cpp:112:10: error: 'mp' was not declared in this scope; did you mean 'p'?
  112 |     a.PB(mp[{ind[pos],ind[pos+1]}]);
      |          ^~
      |          p
islands.cpp:121:10: error: 'mp' was not declared in this scope; did you mean 'tmp'?
  121 |     b.PB(mp[{tmp[i],tmp[i+1]}]);
      |          ^~
      |          tmp
islands.cpp:125:10: error: 'mp2' was not declared in this scope
  125 |     c.PB(mp2[{tmp[i],tmp[i+1]}]);
      |          ^~~
islands.cpp:128:3: error: 'reverse' was not declared in this scope
  128 |   reverse(b.begin,b.end());
      |   ^~~~~~~