Language: C++

#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

vector<int> lan[MAX_N];
int par[MAX_N];
int rank[MAX_N];

void initial(int n){		//初期化
	for(int i=0;i<n;i++){
		par[i] = i;
		rank[i] = 0;
	}
}

int find(int x){		//木の根を求める
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}

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]++;
	}
}

bool same(int x,int y){
	return find(x) == find(y);
}

int main()
{
	int n,m,k,L;
	bool flag = true;
	cin >> n >> m;
	rep(i,n){
		cin >> k;
		rep(j,k){
			scanf("%d",&L);
			lan[L-1].push_back(i);
		}
	}
	initial(n);
	rep(i,m){
		if(!lan[i].empty()){
			rep(j,lan[i].size()-1){
				if(lan[i].size()>=2){
					unite(lan[i][j],lan[i][j+1]);
				}
			}
		}
	}
	rep(i,n-1){
		if(!same(i,i+1)){
			flag = false;
			break;
		}
	}
	if(flag){
		cout << "YES" << "\n";
	}else{
		cout << "NO" << "\n";
	}
}

Compiler output:
a.cc: In function 'void initial(int)':
a.cc:20:17: error: reference to 'rank' is ambiguous
   20 |                 rank[i] = 0;
      |                 ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:15:5: note:                 'int rank [100005]'
   15 | int rank[MAX_N];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:36:12: error: reference to 'rank' is ambiguous
   36 |         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:15:5: note:                 'int rank [100005]'
   15 | int rank[MAX_N];
      |     ^~~~
a.cc:36:22: error: reference to 'rank' is ambiguous
   36 |         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:15:5: note:                 'int rank [100005]'
   15 | int rank[MAX_N];
      |     ^~~~
a.cc:40:20: error: reference to 'rank' is ambiguous
   40 |                 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:15:5: note:                 'int rank [100005]'
   15 | int rank[MAX_N];
      |     ^~~~
a.cc:40:31: error: reference to 'rank' is ambiguous
   40 |                 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:15:5: note:                 'int rank [100005]'
   15 | int rank[MAX_N];
      |     ^~~~
a.cc:41:25: error: reference to 'rank' is ambiguous
   41 |                         rank[x]++;
      |                         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:15:5: note:                 'int rank [100005]'
   15 | int rank[MAX_N];
      |     ^~~~