Language: C++

# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL,LL>> Ppll;
typedef pair<LL, LL> Vec2;
typedef tuple<LL, LL, LL> Tll;
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,n) for(LL i=n-1;i>=0;i--)
struct Edge { LL to,cost; };
vector<Edge>vec[1100000];
bitset<100002>bi[1000002];
LL h, w, n, m, s, t, sum, ans = 0, d[100002];
void DIUX(LL s) {
	for (int i = 0; i < 100002; i++)
		d[i] = INF;
	d[s] = 0;
	priority_queue<Ppll, vector<Ppll>, greater<Ppll>> pq;
	pq.push(make_pair(d[s], Pll(s, 0))); // (cost,頂点番号) 
	while (!pq.empty()) {
		Ppll pp;
		pp = pq.top();
		LL cos = pp.first, vv = pp.second.first, nn = pp.second.second;
		pq.pop();
		if (d[vv] < pp.first)continue;
		rep(i, vec[vv].size())
			if ((nn != vec[vv][i].cost ? 1 : 0) + d[vv] < d[vec[vv][i].to]) {
				d[vec[vv][i].to] = (nn != vec[vv][i].cost ? 1 : 0) + d[vv];
				bi[vv][nn] = 1;
				pq.push(make_pair(d[vec[vv][i].to], Pll(vec[vv][i].to, vec[vv][i].cost)));
			}
			else if((nn != vec[vv][i].cost ? 1 : 0) + d[vv]==d[vec[vv][i].to]&&bi[vv][nn]==0) {
				d[vec[vv][i].to] = (nn != vec[vv][i].cost ? 1 : 0) + d[vv];
				bi[vv][nn] = 1;
				pq.push(make_pair(d[vec[vv][i].to], Pll(vec[vv][i].to, vec[vv][i].cost)));
			}
	}
}

int main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> s >> t >> w;
		vec[s].push_back(Edge{ t,w });
		vec[t].push_back(Edge{ s,w });
	}
	DIUX(1);
	cout << (d[n]==INF?-1:d[n]) << endl;
	return 0;
}

Compiler output:
/tmp/ccPdKQTx.o: in function `DIUX(long long)':
a.cc:(.text+0x2e): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccPdKQTx.o
a.cc:(.text+0x5f): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccPdKQTx.o
a.cc:(.text+0xb6): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccPdKQTx.o
a.cc:(.text+0x16b): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccPdKQTx.o
a.cc:(.text+0x1df): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccPdKQTx.o
a.cc:(.text+0x223): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccPdKQTx.o
a.cc:(.text+0x288): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccPdKQTx.o
a.cc:(.text+0x2cc): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccPdKQTx.o
a.cc:(.text+0x3cb): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccPdKQTx.o
a.cc:(.text+0x45f): relocation truncated to fit: R_X86_64_PC32 against symbol `d' defined in .bss section in /tmp/ccPdKQTx.o
a.cc:(.text+0x4a3): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status