Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn = 400010;
const int inf  = 0x3f3f3f3f;

int n,m,tol,head[maxm];
struct edge
{
    int to,cost,next;
}es[maxm];

void addedge( int u , int v , int w )
{
    es[tol].to = v;
    es[tol].cost = w;
    es[tol].next = head[u];
    head[u] = tol++;
}

struct node
{
    int from,to,cost;
    friend bool operator<( const node&a , const node&b )
    {
        return a.cost<b.cost;
    }
}data[maxm>>1];

int dis[maxn],vis[maxn],used[maxm>>1],pre[maxm>>1],id[maxm>>1],sizes;

int Find( int x )
{
    if ( x!=pre[x] )
        pre[x] = Find( pre[x] );
    return pre[x];
}

void Build( int l , int r )
{
    for ( int i=l ; i<=r ; i++ )
    {
        pre[data[i].to] = data[i].to;
        pre[data[i].from] = data[i].from;
        id[data[i].to] = -1;
        id[data[i].from] = -1;
        used[data[i].to] = 0;
        used[data[i].from] = 0;
    }
    for ( int i=l ; i<=r ; i++ )
    {
        int fx = Find( data[i].from );
        int fy = Find( data[i].to );
        if ( fx!=fy )
            pre[fy] = fx;
    }
    for ( int i=l ; i<=r ; i++ )
    {
        int fx = Find( data[i].from );
        int fy = Find( data[i].to );
        if ( !used[data[i].from] )
        {
            if ( id[fx]==-1 )
                id[fx] = ++sizes;
            addedge( data[i].from , id[fx] , 1 );
            addedge( id[fx] , data[i].from , 1 );
        }
        if ( !used[data[i].to] )
        {
            if ( id[fy]==-1 )
                id[fy] = ++sizes;
            addedge( data[i].to , id[fy] , 1 );
            addedge( id[fy] , data[i].to , 1 );
        }
    }
}

struct point
{
    int pos,dis;
    friend bool operator<( const point&a , const point&b )
    {
        return a.dis>b.dis;
    }
};

void dijkstra()
{
    priority_queue<point>Q;
    for ( int i=1 ; i<=sizes ; i++ )
        dis[i] = inf,vis[i] = 0;
    dis[1] = 0;
    point p,q;
    p.pos = 1;
    p.dis = 0;
    Q.push(p);
    while ( !Q.empty() )
    {
        p = Q.top();
        Q.pop();
        int u = p.pos;
        if ( vis[u] )
            continue;
        vis[u] = 1;
        for ( int i=head[u] ; i!=-1 ; i=es[i].next )
        {
            int v = es[i].to,w = es[i].cost;
            if ( dis[v]>dis[u]+w )
            {
                dis[v] = dis[u]+w;
                p.pos = v;
                p.dis = dis[v];
                Q.push(p);
            }
        }
    }
}

int main()
{
    for ( ; scanf ( "%d%d" , &n , &m )==2 ; )
    {
        for ( int i=1 ; i<=m ; i++ )
            scanf ( "%d%d%d" , &data[i].from , &data[i].to , &data[i].cost );
        sort ( data+1 , data+m+1 );
        tol = 0;
        sizes = n;
        memset ( head , -1 , sizeof(head) );
        for ( int i=1 ; i<=m ; i++ )
        {
            int l=i,r=i;
            while ( r+1<=m&&data[r+1].cost==data[i].cost )
                r++;
            Build( l , r );
            i = r;
        }
        dijkstra();
        if ( dis[n]==inf )
            dis[n] = -2;
        printf ( "%d\n" , dis[n]>>1 );
    }
    return 0;
}


Compiler output:
a.cc:6:18: error: 'maxm' was not declared in this scope; did you mean 'maxn'?
    6 | int n,m,tol,head[maxm];
      |                  ^~~~
      |                  maxn
a.cc:10:5: error: 'maxm' was not declared in this scope; did you mean 'maxn'?
   10 | }es[maxm];
      |     ^~~~
      |     maxn
a.cc: In function 'void addedge(int, int, int)':
a.cc:14:5: error: 'es' was not declared in this scope
   14 |     es[tol].to = v;
      |     ^~
a.cc:16:20: error: 'head' was not declared in this scope; did you mean 'read'?
   16 |     es[tol].next = head[u];
      |                    ^~~~
      |                    read
a.cc: At global scope:
a.cc:27:7: error: 'maxm' was not declared in this scope; did you mean 'maxn'?
   27 | }data[maxm>>1];
      |       ^~~~
      |       maxn
a.cc:29:30: error: 'maxm' was not declared in this scope; did you mean 'maxn'?
   29 | int dis[maxn],vis[maxn],used[maxm>>1],pre[maxm>>1],id[maxm>>1],sizes;
      |                              ^~~~
      |                              maxn
a.cc:29:43: error: 'maxm' was not declared in this scope; did you mean 'maxn'?
   29 | int dis[maxn],vis[maxn],used[maxm>>1],pre[maxm>>1],id[maxm>>1],sizes;
      |                                           ^~~~
      |                                           maxn
a.cc:29:55: error: 'maxm' was not declared in this scope; did you mean 'maxn'?
   29 | int dis[maxn],vis[maxn],used[maxm>>1],pre[maxm>>1],id[maxm>>1],sizes;
      |                                                       ^~~~
      |                                                       maxn
a.cc: In function 'int Find(int)':
a.cc:33:13: error: 'pre' was not declared in this scope; did you mean 'pread'?
   33 |     if ( x!=pre[x] )
      |             ^~~
      |             pread
a.cc:35:12: error: 'pre' was not declared in this scope; did you mean 'pread'?
   35 |     return pre[x];
      |            ^~~
      |            pread
a.cc: In function 'void Build(int, int)':
a.cc:42:9: error: 'pre' was not declared in this scope
   42 |         pre[data[i].to] = data[i].to;
      |         ^~~
a.cc:42:17: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   42 |         pre[data[i].to] = data[i].to;
      |                 ^
a.cc:42:31: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   42 |         pre[data[i].to] = data[i].to;
      |                               ^
a.cc:43:17: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   43 |         pre[data[i].from] = data[i].from;
      |                 ^
a.cc:43:33: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   43 |         pre[data[i].from] = data[i].from;
      |                                 ^
a.cc:44:9: error: 'id' was not declared in this scope; did you mean 'i'?
   44 |         id[data[i].to] = -1;
      |         ^~
      |         i
a.cc:44:16: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   44 |         id[data[i].to] = -1;
      |                ^
a.cc:45:16: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   45 |         id[data[i].from] = -1;
      |                ^
a.cc:46:9: error: 'used' was not declared in this scope
   46 |         used[data[i].to] = 0;
      |         ^~~~
a.cc:46:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   46 |         used[data[i].to] = 0;
      |                  ^
a.cc:47:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   47 |         used[data[i].from] = 0;
      |                  ^
a.cc:51:28: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   51 |         int fx = Find( data[i].from );
      |                            ^
a.cc:52:28: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   52 |         int fy = Find( data[i].to );
      |                            ^
a.cc:54:13: error: 'pre' was not declared in this scope
   54 |             pre[fy] = fx;
      |             ^~~
a.cc:58:28: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   58 |         int fx = Find( data[i].from );
      |                            ^
a.cc:59:28: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   59 |         int fy = Find( data[i].to );
      |                            ^
a.cc:60:15: error: 'used' was not declared in this scope
   60 |         if ( !used[data[i].from] )
      |               ^~~~
a.cc:60:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   60 |         if ( !used[data[i].from] )
      |                        ^
a.cc:62:18: error: 'id' was not declared in this scope; did you mean 'i'?
   62 |             if ( id[fx]==-1 )
      |                  ^~
      |                  i
a.cc:64:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   64 |             addedge( data[i].from , id[fx] , 1 );
      |                          ^
a.cc:64:37: error: 'id' was not declared in this scope; did you mean 'i'?
   64 |             addedge( data[i].from , id[fx] , 1 );
      |                                     ^~
      |                                     i
a.cc:65:35: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   65 |             addedge( id[fx] , data[i].from , 1 );
      |                                   ^
a.cc:67:15: error: 'used' was not declared in this scope
   67 |         if ( !used[data[i].to] )
      |               ^~~~
a.cc:67:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   67 |         if ( !used[data[i].to] )
      |                        ^
a.cc:69:18: error: 'id' was not declared in this scope; did you mean 'i'?
   69 |             if ( id[fy]==-1 )
      |                  ^~
      |                  i
a.cc:71:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   71 |             addedge( data[i].to , id[fy] , 1 );
      |                          ^
a.cc:71:35: error: 'id' was not declared in this scope; did you mean 'i'?
   71 |             addedge( data[i].to , id[fy] , 1 );
      |                                   ^~
      |                                   i
a.cc:72:35: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   72 |             addedge( id[fy] , data[i].to , 1 );
      |                                   ^
a.cc: In function 'void dijkstra()':
a.cc:104:21: error: 'head' was not declared in this scope; did you mean 'read'?
  104 |         for ( int i=head[u] ; i!=-1 ; i=es[i].next )
      |                     ^~~~
      |                     read
a.cc:104:41: error: 'es' was not declared in this scope
  104 |         for ( int i=head[u] ; i!=-1 ; i=es[i].next )
      |                                         ^~
a.cc:107:32: error: 'w' was not declared in this scope
  107 |             if ( dis[v]>dis[u]+w )
      |                                ^
a.cc: In function 'int main()':
a.cc:123:37: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  123 |             scanf ( "%d%d%d" , &data[i].from , &data[i].to , &data[i].cost );
      |                                     ^
a.cc:123:53: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  123 |             scanf ( "%d%d%d" , &data[i].from , &data[i].to , &data[i].cost );
      |                                                     ^
a.cc:123:67: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  123 |             scanf ( "%d%d%d" , &data[i].from , &data[i].to , &data[i].cost );
      |                                                                   ^
a.cc:124:20: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator+'
  124 |         sort ( data+1 , data+m+1 );
      |                ~~~~^~
a.cc:124:29: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator+'
  124 |         sort ( data+1 , data+m+1 );
      |                         ~~~~^~
a.cc:127:18: error: 'head' was not declared in this scope; did you mean 'read'?
  127 |         memset ( head , -1 , sizeof(head) );
      |                  ^~~~
      |                  read
a.cc:131:33: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  131 |             while ( r+1<=m&&data[r+1].cost==data[i].cost )
      |                                 ^
a.cc:131:49: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  131 |             while ( r+1<=m&&data[r+1].cost==data[i].cost )
      |                                                 ^