Language: C++

#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>

using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)

vector<int> parent, rank;

int find(int a){
	if(parent[a]!=a){
		parent[a] = find(parent[a]);
	}
	return parent[a];
}

void uni(int a, int b){
	int pa=find(a);
	int pb=find(b);
	if (rank[pa]>rank[pb]){
		parent[pb]=pa;
	}else{
		parent[pa]=pb;
	}
	if(rank[pb]==rank[pa]){
		rank[pa]++;
	}
}

int main(){
	int n, m;
	cin>>n>>m;
	forn(i, m){
		parent.push_back(i);
		rank.push_back(0);
	}
	bool aparece[m];
	forn(i, m){
		aparece[i]=false;
	}
	forn(i, n){
		int k;
		cin>>k;
		int lp;
		forn(j, k){
			int l;
			cin>>l;
			l--;
			aparece[l]=true;
			if(j==0){
				lp=l;
			}else{
				//cout<<"uno  "<<lp<<"  "<<l<<endl;
				uni(lp, l);
			}
		}
	}
	set<int> ss;
	forn(i, m){
		if(aparece[i]) {
			find(i);
			ss.insert(parent[i]);
		}
	}
	if(ss.size()==1){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}


Compiler output:
a.cc: In function 'void uni(int, int)':
a.cc:25:13: error: reference to 'rank' is ambiguous
   25 |         if (rank[pa]>rank[pb]){
      |             ^~~~
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:13:21: note:                 'std::vector<int> rank'
   13 | vector<int> parent, rank;
      |                     ^~~~
a.cc:25:22: error: reference to 'rank' is ambiguous
   25 |         if (rank[pa]>rank[pb]){
      |                      ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:21: note:                 'std::vector<int> rank'
   13 | vector<int> parent, rank;
      |                     ^~~~
a.cc:30:12: error: reference to 'rank' is ambiguous
   30 |         if(rank[pb]==rank[pa]){
      |            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:21: note:                 'std::vector<int> rank'
   13 | vector<int> parent, rank;
      |                     ^~~~
a.cc:30:22: error: reference to 'rank' is ambiguous
   30 |         if(rank[pb]==rank[pa]){
      |                      ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:21: note:                 'std::vector<int> rank'
   13 | vector<int> parent, rank;
      |                     ^~~~
a.cc:31:17: error: reference to 'rank' is ambiguous
   31 |                 rank[pa]++;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:21: note:                 'std::vector<int> rank'
   13 | vector<int> parent, rank;
      |                     ^~~~
a.cc: In function 'int main()':
a.cc:40:17: error: reference to 'rank' is ambiguous
   40 |                 rank.push_back(0);
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:13:21: note:                 'std::vector<int> rank'
   13 | vector<int> parent, rank;
      |                     ^~~~