Language: C++

#pragma GCC optimize "O3"
#pragma GCC target "avx"
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


int N, M;
vector<pair<int, int>> G[100010]; // G[i] := i->j color
//dist[i<<32+j] := 頂点iへ路線 jでつくときのコストの最小値
unordered_map<uint64_t> dist;
using PP = pair<int, pair<int, int>>;

uint64_t func(uint64_t x, uint32_t y) {
    return (x << 32 + y);
}
void dijkstra(int start){
    priority_queue<PP, vector<PP>, greater<PP>> que; // コスト 位置 路線
    // dist[start][-1] = 0;
    dist[func(start, -1)] = 0;
    que.push(mp(0, mp(start, -1)));
    
    while(!que.empty()){
        auto tm = que.top(); que.pop();
       	int cost = tm.fi, u = tm.se.fi, color = tm.se.se;
        if(dist[func(u, color)] < cost) continue; // これでTLE回避してください
        if(u == N - 1) break;
        for(auto tm : G[u]){
            int v = tm.fi, nc = tm.se; // u->v nc
            int ncost = cost + ((nc == color) ? 0 : 1);
            if(dist.count(func(v, nc)) == 0 || dist[func(v, nc)] > ncost){
                dist[func(v, nc)] = ncost;
                que.push(mp(ncost, mp(v, nc)));
            }
        }
    }
    
}

int main(void){
	scanf("%d %d", &N, &M);
	rep(i, M){
		int p, q, c; scanf("%d %d %d", &p, &q, &c);
		p--, q--;
		G[p].emplace_back(mp(q, c)), G[q].emplace_back(mp(p, c));
	}
	dijkstra(0);
	int mi = INF;
	rep(i, 1000001){
        if(dist.count(func(N - 1, i))) chmin(mi, dist[func(N - 1, i)]);
    }
    if(mi != INF) printf("%d\n", mi);
    else printf("-1\n");
	return 0;
}

Compiler output:
a.cc:39:15: error: 'uint64_t' was not declared in this scope
   39 | unordered_map<uint64_t> dist;
      |               ^~~~~~~~
a.cc:14:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
   13 | #include <functional>
  +++ |+#include <cstdint>
   14 | using namespace std;
a.cc:39:23: error: wrong number of template arguments (1, should be at least 2)
   39 | unordered_map<uint64_t> dist;
      |                       ^
In file included from /usr/include/c++/14/unordered_map:41,
                 from a.cc:11:
/usr/include/c++/14/bits/unordered_map.h:109:11: note: provided for 'template<class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> class std::unordered_map'
  109 |     class unordered_map
      |           ^~~~~~~~~~~~~
a.cc:42:1: error: 'uint64_t' does not name a type
   42 | uint64_t func(uint64_t x, uint32_t y) {
      | ^~~~~~~~
a.cc:42:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc: In function 'void dijkstra(int)':
a.cc:48:10: error: 'func' was not declared in this scope
   48 |     dist[func(start, -1)] = 0;
      |          ^~~~
a.cc:59:21: error: request for member 'count' in 'dist', which is of non-class type 'int'
   59 |             if(dist.count(func(v, nc)) == 0 || dist[func(v, nc)] > ncost){
      |                     ^~~~~
a.cc: In function 'int main()':
a.cc:78:17: error: request for member 'count' in 'dist', which is of non-class type 'int'
   78 |         if(dist.count(func(N - 1, i))) chmin(mi, dist[func(N - 1, i)]);
      |                 ^~~~~
a.cc:78:23: error: 'func' was not declared in this scope
   78 |         if(dist.count(func(N - 1, i))) chmin(mi, dist[func(N - 1, i)]);
      |                       ^~~~