Language: C++

#include<bits/stdc++.h>
using namespace std;
#define MAX 1000005 
#define pb push_back
#define mp make_pair
typedef pair<int,int> pi;

int N, M, a, b, c, par[MAX], rank[MAX], step[MAX], mx=-1, id[MAX];
vector<pi> jie[MAX];
vector<int> shua[MAX];
bool vis[MAX];

inline int find(int x)
{
	if(x==par[x])
		return x;
	return par[x]=find(par[x]);
}
inline void inint(int x)
{
	par[x]=x;
	rank[x]=0;
}
inline void unite(int x, int y)
{
	x=find(x), y=find(y);
	if(x==y)
		return;
	if(rank[x]<rank[y])
	{
		par[x]=y;
		return;
	}
	par[y]=x;
	if(rank[x]==rank[y])
		rank[x]++;
	return;
}

int main()
{
	memset(step, -1, sizeof(step));
	scanf("%d %d", &N, &M);
	while(M--)
	{
		scanf("%d %d %d", &a, &b, &c);
		mx=max(mx, c);
		a--, b--, c--;
		jie[c].pb(mp(a, b));
	}
	int yy=N;
	for(int i=0; i<mx; i++)
	{
		for(vector<pi>::iterator it=jie[i].begin(); it!=jie[i].end(); it++)
		{
			pi hh=*it;
			inint(hh.first);
			id[hh.first]=-1;
			vis[hh.first]=false;
			
			inint(hh.second);
			id[hh.second]=-1;
			vis[hh.second]=false;
		}
		for(vector<pi>::iterator it=jie[i].begin(); it!=jie[i].end(); it++)
		{
			pi hh=*it;
			unite(hh.first, hh.second);
		}
		for(vector<pi>::iterator it=jie[i].begin(); it!=jie[i].end(); it++)
		{
			pi hh=*it;
			if(!vis[hh.first])
			{
				vis[hh.first]=true;
				int r=find(hh.first);
				if(id[r]==-1)
					id[r]=yy++;
				shua[id[r]].pb(hh.first);
				shua[hh.first].pb(id[r]);
			}
			
			swap(hh.first, hh.second);
			
			if(!vis[hh.first])
			{
				vis[hh.first]=true;
				int r=find(hh.first);
				if(id[r]==-1)
					id[r]=yy++;
				shua[id[r]].pb(hh.first);
				shua[hh.first].pb(id[r]);
			}
		}
	}
	queue<int> q;
	q.push(0);
	step[0]=0;
	while(!q.empty())
	{
		int t=q.front();
		q.pop();
		if(step[N-1]>-1)
			break;
		for(int i=0; i<shua[t].size(); i++)
		{
			if(step[shua[t][i]]==-1)
			{
				step[shua[t][i]]=step[t]+1;
				q.push(shua[t][i]);
			}
		}
	}
	if(step[N-1]==-1)
		printf("%d", -1);
	else
		printf("%d", step[N-1]/2);
	return 0;
}


Compiler output:
a.cc: In function 'void inint(int)':
a.cc:22:9: error: reference to 'rank' is ambiguous
   22 |         rank[x]=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:8:30: note:                 'int rank [1000005]'
    8 | int N, M, a, b, c, par[MAX], rank[MAX], step[MAX], mx=-1, id[MAX];
      |                              ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:29:12: error: reference to 'rank' is ambiguous
   29 |         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:8:30: note:                 'int rank [1000005]'
    8 | int N, M, a, b, c, par[MAX], rank[MAX], step[MAX], mx=-1, id[MAX];
      |                              ^~~~
a.cc:29:20: error: reference to 'rank' is ambiguous
   29 |         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:8:30: note:                 'int rank [1000005]'
    8 | int N, M, a, b, c, par[MAX], rank[MAX], step[MAX], mx=-1, id[MAX];
      |                              ^~~~
a.cc:35:12: error: reference to 'rank' is ambiguous
   35 |         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:8:30: note:                 'int rank [1000005]'
    8 | int N, M, a, b, c, par[MAX], rank[MAX], step[MAX], mx=-1, id[MAX];
      |                              ^~~~
a.cc:35:21: error: reference to 'rank' is ambiguous
   35 |         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:8:30: note:                 'int rank [1000005]'
    8 | int N, M, a, b, c, par[MAX], rank[MAX], step[MAX], mx=-1, id[MAX];
      |                              ^~~~
a.cc:36:17: error: reference to 'rank' is ambiguous
   36 |                 rank[x]++;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:30: note:                 'int rank [1000005]'
    8 | int N, M, a, b, c, par[MAX], rank[MAX], step[MAX], mx=-1, id[MAX];
      |                              ^~~~