Language: C++

#include <bits/stdc++.h>
#define MAXN 1000000
#define MOD 1000000007
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
int n;
int tot;
int par[NAXN];
int id[MAXN];
bool used[MAXN];
vector<p>c[MAXN];
vector<int>v[MAXN];
struct node
{
    int idd,step;
};
void init()
{
    for(int i=1;i<=n;i++)
    {
        par[i]=i;
        id[i]=0;
        used[i]=false;
    }
}
int Find(int x)
{
    if(par[x]==x)return x;
    return par[x]=Find(par[x]);
}
void unite(int x,int y)
{
    x=Find(x);y=Find(y);
    par[x]=y;
}
int main()
{
    int m,x,y,z;
    int MAX=0;
    scanf("%d%d",&n,&m);
    while(m--)
    {
        scanf("%d%d%d",&x,&y,&z);
        c[z].push_back(make_pair(x,y));
        MAX=max(MAX,z);
    }
    tot=n;
    for(int i=1;i<=MAX;i++)
    {
        int len=c[i].size();
        init();
        for(int j=0;j<len;j++)
            unite(c[i][j].first,c[i][j].second);
        for(int j=0;j<len;j++)
        {
            int x=c[i][j].first,y=c[i][j].second;
            int fx=Find(x),fy=Find(y);
            if(id[fx]==0)id[fx]=++tot;
            if(id[fy]==0)id[fy]=++tot;
            if(!used[x])
            {
                used[x]=true;
                v[x].push_back(id[fx]);
                //printf("(%d,%d)",x,id[fx]);
                v[id[fx]].push_back(x);
            }
            if(!used[y])
            {
                used[y]=true;
                v[y].push_back(id[fy]);
                //printf("(%d,%d)",y,id[fy]);
                v[id[fy]].push_back(y);
            }
        }
        //printf("\n");
    }
    memset(used,0,sizeof(used));
    int ans=-2;
    queue<node>q;
    q.push(node{1,0});
    while(!q.empty())
    {
        node temp=q.front();
        q.pop();
        x=temp.idd;y=temp.step;
        int len=v[x].size();
        for(int i=0;i<len;i++)
        {
            if(!used[v[x][i]])
            {
                if(v[x][i]==n)
                {
                    ans=y+1;
                    break;
                }
                used[v[x][i]]=true;
                q.push(node{v[x][i],y+1});
                //printf("(%d,%d)",v[x][i],y+1);
            }
        }
    }
    printf("%d\n",ans/2);
    return 0;
}


Compiler output:
a.cc:10:9: error: 'NAXN' was not declared in this scope; did you mean 'MAXN'?
   10 | int par[NAXN];
      |         ^~~~
      |         MAXN
a.cc: In function 'void init()':
a.cc:23:9: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   23 |         par[i]=i;
      |         ^~~
      |         __pstl::execution::v1::par
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/14/algorithm:86,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc: In function 'int Find(int)':
a.cc:30:8: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   30 |     if(par[x]==x)return x;
      |        ^~~
      |        __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc:31:12: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   31 |     return par[x]=Find(par[x]);
      |            ^~~
      |            __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc: In function 'void unite(int, int)':
a.cc:36:5: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   36 |     par[x]=y;
      |     ^~~
      |     __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~