Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int par[100000];//親
int rank[100000];//木の深さ
//初期化
void init(int N){
  FOR(i,0,N){
    par[i]=i;
    rank[i]=0;
  }
}
//木の根を求める
int find(int X){
  if(par[X]==X){
    return X;
  }else{
    return par[X]=find(par[X]);
  }
}
//Xの属する集合とYの属する集合を併合
void unite(int X,int Y){
  X=find(X);
  Y=find(Y);
  if(X==Y){
    return;
  }
  if(rank[X]<rank[Y]){
    par[X]=Y;
  }else{
    par[Y]=X;
    if(rank[X]==rank[Y]){
      rank[X]++;
    }
  }
}
//XとYが同じ集合に属するか否か
bool same(int X,int Y){
  return  find(X)==find(Y);
}
//
int N,M,K;
set<int> S[100000];
int main(){
	cin>>N>>M;
	FOR(i,0,N){
		cin>>K;
		FOR(j,0,K){
			int l;
			cin>>l;
			l--;
			S[l].insert(i);
		}
	}
	init(N);
	FOR(i,0,M){
		set<int>::iterator it=S[i].begin();
		if(it==S[i].end()){
			continue;
		}
		int num=*it;
		it++;
		while(it!=S[i].end()){
			unite(num,*it);
			num=*it;
			it++;
		}
	}
	FOR(i,0,N-1){
		if(!same(i,i+1)){
			YES(0);
			return 0;
		}
	}
	YES(1);
	return 0;
}


Compiler output:
a.cc: In function 'void init(int)':
a.cc:44:5: error: reference to 'rank' is ambiguous
   44 |     rank[i]=0;
      |     ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:39:5: note:                 'int rank [100000]'
   39 | int rank[100000];//木の深さ
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:62:6: error: reference to 'rank' is ambiguous
   62 |   if(rank[X]<rank[Y]){
      |      ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:39:5: note:                 'int rank [100000]'
   39 | int rank[100000];//木の深さ
      |     ^~~~
a.cc:62:14: error: reference to 'rank' is ambiguous
   62 |   if(rank[X]<rank[Y]){
      |              ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:39:5: note:                 'int rank [100000]'
   39 | int rank[100000];//木の深さ
      |     ^~~~
a.cc:66:8: error: reference to 'rank' is ambiguous
   66 |     if(rank[X]==rank[Y]){
      |        ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:39:5: note:                 'int rank [100000]'
   39 | int rank[100000];//木の深さ
      |     ^~~~
a.cc:66:17: error: reference to 'rank' is ambiguous
   66 |     if(rank[X]==rank[Y]){
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:39:5: note:                 'int rank [100000]'
   39 | int rank[100000];//木の深さ
      |     ^~~~
a.cc:67:7: error: reference to 'rank' is ambiguous
   67 |       rank[X]++;
      |       ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:39:5: note:                 'int rank [100000]'
   39 | int rank[100000];//木の深さ
      |     ^~~~