Language: C++

#include <bits/stdc++.h>
#define for(i, n) for(int i=0; i<n; i++)
using namespace std;

long xsum=0,ysum=0,K=0;
bool visit[100005];

void cal(int i,bool xory,long *x,long *y,long N){
visit[i]=true;
for(j, N){
  if(visit[j] || i==j) continue;
  if( x[i]==x[j] || y[i]==y[j]){
    visit[j] = true;
    if(xory){
      ysum++;
      xory = false;
    }else{
      xsum++;
      xory = true;
    }
    cal(j,xory,x,y,N);
  }
}
}

int main(){

long N;
cin >> N;
long x[N], y[N];
bool xory;
for(i, N) cin >> x[i] >> y[i];
for(i, N) visit[i] = false;

for(i, N){
  if(visit[i]) continue;
  xsum = 1;
  ysum = 1;
  xory = true;
  cal(i,xory,x,y,N);
  xory = false;
  cal(i,xory,x,y,N);
  K += xsum*ysum;
}
cout << K-N << endl;
return 0;

}
メッセージ入力


メモを書く

Compiler output:
a.cc: In function 'void cal(int, bool, long int*, long int*, long int)':
a.cc:9:1: error: reference to 'visit' is ambiguous
    9 | visit[i]=true;
      | ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:6: note:                 'bool visit [100005]'
    6 | bool visit[100005];
      |      ^~~~~
a.cc:11:6: error: reference to 'visit' is ambiguous
   11 |   if(visit[j] || i==j) continue;
      |      ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:6: note:                 'bool visit [100005]'
    6 | bool visit[100005];
      |      ^~~~~
a.cc:13:5: error: reference to 'visit' is ambiguous
   13 |     visit[j] = true;
      |     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:6: note:                 'bool visit [100005]'
    6 | bool visit[100005];
      |      ^~~~~
a.cc: In function 'int main()':
a.cc:33:11: error: reference to 'visit' is ambiguous
   33 | for(i, N) visit[i] = false;
      |           ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:6: note:                 'bool visit [100005]'
    6 | bool visit[100005];
      |      ^~~~~
a.cc:36:6: error: reference to 'visit' is ambiguous
   36 |   if(visit[i]) continue;
      |      ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:6:6: note:                 'bool visit [100005]'
    6 | bool visit[100005];
      |      ^~~~~
a.cc: At global scope:
a.cc:49:1: error: '\U000030e1\U000030c3\U000030bb\U000030fc\U000030b8\U00005165\U0000529b' does not name a type
   49 | メッセージ入力
      | ^~~~~~~~~~~~~~