Submission #394866

# Submission time Handle Problem Language Result Execution time Memory
394866 2021-04-27T11:43:18 Z irmuun Swapping Cities (APIO20_swap) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
int a,b,i,n,m,par[100000],edge[100000],size[100000];
bool ans[100000];
pair<int, pair<int,int> >p[200000];
int find(int x){
  while(x!=par[x]){
    x=par[x];
  }
  return x;
}
bool connect(int a,int b){
  if(find(a)==find(b)){
    return true;
  }
  else{
    return false;
  }
}
void unite(int a,int b){
  edge[a]++;
  edge[b]++;
  a=find(a);
  b=find(b);
  if(size[a]<size[b]){
    swap(a,b);
  }
  if(edge[a]==3||edge[b]==3||ans[b]==true){
    ans[a]=true;
  }
  par[b]=a;
  size[a]+=size[b];
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
  m=M;
  n=N;
  for(i=0;i<M;i++){
    p[i].first=W[i];
    p[i].second.first=V[i];
    p[i].second.second=U[i];
  }
  sort(p,p+m);
}
int getMinimumFuelCapacity(int X, int Y) {
  for(i=0;i<100000;i++){
    par[i]=i;
    size[i]=1;
    edge[i]=0;
  }
  for(i=0;i<m;i++){
    unite(p[i].second.first,p[i].second.second);
    if(connect(X,Y)==true){
      if(ans[find(X)]==true||ans[find(Y)]==true){
        return p[i].first;
      }
    }
  }
  return -1;
}

Compilation message

swap.cpp: In function 'void unite(int, int)':
swap.cpp:25:6: error: reference to 'size' is ambiguous
   25 |   if(size[a]<size[b]){
      |      ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from swap.cpp:1:
/usr/include/c++/9/bits/range_access.h:252:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  252 |     size(const _Tp (&/*__array*/)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:242:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  242 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
swap.cpp:3:40: note:                 'int size [100000]'
    3 | int a,b,i,n,m,par[100000],edge[100000],size[100000];
      |                                        ^~~~
swap.cpp:25:14: error: reference to 'size' is ambiguous
   25 |   if(size[a]<size[b]){
      |              ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from swap.cpp:1:
/usr/include/c++/9/bits/range_access.h:252:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  252 |     size(const _Tp (&/*__array*/)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:242:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  242 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
swap.cpp:3:40: note:                 'int size [100000]'
    3 | int a,b,i,n,m,par[100000],edge[100000],size[100000];
      |                                        ^~~~
swap.cpp:32:3: error: reference to 'size' is ambiguous
   32 |   size[a]+=size[b];
      |   ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from swap.cpp:1:
/usr/include/c++/9/bits/range_access.h:252:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  252 |     size(const _Tp (&/*__array*/)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:242:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  242 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
swap.cpp:3:40: note:                 'int size [100000]'
    3 | int a,b,i,n,m,par[100000],edge[100000],size[100000];
      |                                        ^~~~
swap.cpp:32:12: error: reference to 'size' is ambiguous
   32 |   size[a]+=size[b];
      |            ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from swap.cpp:1:
/usr/include/c++/9/bits/range_access.h:252:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  252 |     size(const _Tp (&/*__array*/)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:242:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  242 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
swap.cpp:3:40: note:                 'int size [100000]'
    3 | int a,b,i,n,m,par[100000],edge[100000],size[100000];
      |                                        ^~~~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:47:5: error: reference to 'size' is ambiguous
   47 |     size[i]=1;
      |     ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from swap.cpp:1:
/usr/include/c++/9/bits/range_access.h:252:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  252 |     size(const _Tp (&/*__array*/)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:242:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  242 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
swap.cpp:3:40: note:                 'int size [100000]'
    3 | int a,b,i,n,m,par[100000],edge[100000],size[100000];
      |                                        ^~~~