Language: C++

#define PB push_back
#define SZ(x) (int)x.size()
#define MP make_pair
#define F first
#define S second
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
const int maxn=1e5+5;
struct Edge {int from,to,type;};
vector<Edge> edges;
vector<int> G[maxn];
map<int,int> d[maxn];
int done[maxn],Mind[maxn];
int n;
const int INF=0x3f3f3f3f;
int dijkstra(const int& st,const int& ed)
{
    priority_queue<piii,vector<piii>,greater<piii> > pq;
    for(int i=0;i<n;i++) d[i].clear(),done[i]=0,Mind[i]=INF;
    pq.push(MP(MP(0,st),-1));
    Mind[st]=0;
    while(!pq.empty())
    {
        piii x=pq.top();pq.pop();
        int now=x.F.S,lasttype=x.S,noww=x.F.F;
        if(done[now]) continue;
        done[now]=1;
        for(const int& num:G[now])
        {
            Edge& e=edges[num];
            int to = e.from == now ? e.to : e.from;
            if(Mind[to]+1>noww+(lasttype==e.type?0:1) &&
                (!(d[to].count(e.type)) || d[to][e.type]>noww+(lasttype == e.type?0:1)))
            {
                d[to][e.type]=noww+(lasttype == e.type?0:1);
                Mind[to]=min(Mind[to],noww+(lasttype== e.type?0:1));
                pq.push(MP(MP(noww+(lasttype == e.type?0:1),to),e.type));
            }
        }
    }
    int ans=INF;
    for(auto&& it:d[ed]) ans=min(ans,it.S);
    return ans == INF ? -1 : ans;
}
int main()
{
    int m;
    scanf("%d%d",&n,&m);
    for(int i=0,a,b,c;i<m;i++)
    {
        scanf("%d%d%d",&a,&b,&c);a--,b--;
        edges.PB((Edge){a,b,c});
        G[a].PB(SZ(edges)-1);
        G[b].PB(SZ(edges)-1);
    }
    printf("%d\n",dijkstra(0,n-1));
}



Compiler output:
a.cc:7:9: error: 'pair' does not name a type
    7 | typedef pair<int,int> pii;
      |         ^~~~
a.cc:8:9: error: 'pair' does not name a type
    8 | typedef pair<pii,int> piii;
      |         ^~~~
a.cc:11:1: error: 'vector' does not name a type
   11 | vector<Edge> edges;
      | ^~~~~~
a.cc:12:1: error: 'vector' does not name a type
   12 | vector<int> G[maxn];
      | ^~~~~~
a.cc:13:1: error: 'map' does not name a type
   13 | map<int,int> d[maxn];
      | ^~~
a.cc: In function 'int dijkstra(const int&, const int&)':
a.cc:19:5: error: 'priority_queue' was not declared in this scope
   19 |     priority_queue<piii,vector<piii>,greater<piii> > pq;
      |     ^~~~~~~~~~~~~~
a.cc:1:1: note: 'std::priority_queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
  +++ |+#include <queue>
    1 | #define PB push_back
a.cc:19:20: error: 'piii' was not declared in this scope
   19 |     priority_queue<piii,vector<piii>,greater<piii> > pq;
      |                    ^~~~
a.cc:19:25: error: 'vector' was not declared in this scope
   19 |     priority_queue<piii,vector<piii>,greater<piii> > pq;
      |                         ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | #define PB push_back
a.cc:19:37: error: expected primary-expression before ',' token
   19 |     priority_queue<piii,vector<piii>,greater<piii> > pq;
      |                                     ^
a.cc:19:38: error: 'greater' was not declared in this scope
   19 |     priority_queue<piii,vector<piii>,greater<piii> > pq;
      |                                      ^~~~~~~
a.cc:19:52: error: expected primary-expression before '>' token
   19 |     priority_queue<piii,vector<piii>,greater<piii> > pq;
      |                                                    ^
a.cc:19:54: error: 'pq' was not declared in this scope
   19 |     priority_queue<piii,vector<piii>,greater<piii> > pq;
      |                                                      ^~
a.cc:20:26: error: 'd' was not declared in this scope
   20 |     for(int i=0;i<n;i++) d[i].clear(),done[i]=0,Mind[i]=INF;
      |                          ^
a.cc:3:12: error: 'make_pair' was not declared in this scope
    3 | #define MP make_pair
      |            ^~~~~~~~~
a.cc:21:16: note: in expansion of macro 'MP'
   21 |     pq.push(MP(MP(0,st),-1));
      |                ^~
a.cc:1:1: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | #define PB push_back
a.cc:3:12: error: 'make_pair' was not declared in this scope
    3 | #define MP make_pair
      |            ^~~~~~~~~
a.cc:21:13: note: in expansion of macro 'MP'
   21 |     pq.push(MP(MP(0,st),-1));
      |             ^~
a.cc:3:12: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
    3 | #define MP make_pair
      |            ^~~~~~~~~
a.cc:21:13: note: in expansion of macro 'MP'
   21 |     pq.push(MP(MP(0,st),-1));
      |             ^~
a.cc:25:13: error: expected ';' before 'x'
   25 |         piii x=pq.top();pq.pop();
      |             ^~
      |             ;
a.cc:26:17: error: 'x' was not declared in this scope
   26 |         int now=x.F.S,lasttype=x.S,noww=x.F.F;
      |                 ^
a.cc:29:28: error: 'G' was not declared in this scope
   29 |         for(const int& num:G[now])
      |                            ^
a.cc:31:21: error: 'edges' was not declared in this scope
   31 |             Edge& e=edges[num];
      |                     ^~~~~
a.cc:33:27: error: 'noww' was not declared in this scope; did you mean 'now'?
   33 |             if(Mind[to]+1>noww+(lasttype==e.type?0:1) &&
      |                           ^~~~
      |                           now
a.cc:33:33: error: 'lasttype' was not declared in this scope
   33 |             if(Mind[to]+1>noww+(lasttype==e.type?0:1) &&
      |                                 ^~~~~~~~
a.cc:34:20: error: 'd' was not declared in this scope
   34 |                 (!(d[to].count(e.type)) || d[to][e.type]>noww+(lasttype == e.type?0:1)))
      |                    ^
a.cc:37:26: error: 'min' was not declared in this scope
   37 |                 Mind[to]=min(Mind[to],noww+(lasttype== e.type?0:1));
      |                          ^~~
a.cc:43:19: error: 'd' was not declared in this scope; did you mean 'ed'?
   43 |     for(auto&& it:d[ed]) ans=min(ans,it.S);
      |                   ^
      |                   ed
a.cc:43:30: error: 'min' was not declared in this scope
   43 |     for(auto&& it:d[ed]) ans=min(ans,it.S);
      |                              ^~~
a.cc: In function 'int main()':
a.cc:49:5: error: 'scanf' was not declared in this scope
   49 |     scanf("%d%d",&n,&m);
      |     ^~~~~
a.cc:53:9: error: 'edges' was not declared in this scope
   53 |         edges.PB((Edge){a,b,c});
      |         ^~~~~
a.cc:54:9: error: 'G' was not declared in this scope
   54 |         G[a].PB(SZ(edges)-1);
      |         ^
a.cc:57:5: error: 'printf' was not declared in this scope
   57 |     printf("%d\n",dijkstra(0,n-1));
      |     ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | #define PB push_back