Language: C++

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int long long

//どう辺をはって、最短経路問題を考えるか
void solve() {
	int n, m; cin >> n >> m;
    vector<P> pairs;
    rep(i, n) {
        pairs.pb(P(i, -1)); //別の点を作る
    }
    rep(i, m) {
        cin >> p[i] >> q[i] >> c[i];
        --p[i]; --q[i];
        pairs.pb(P(p[i], c[i]));
        pairs.pb(P(q[i], c[i]));
    }

    sort(all(pairs));
    pairs.erase(unique(all(pairs)), pairs.end());
    int sz = pairs.size();
    map<P, int> mp; //逆引き
    rep(i, sz) {
        mp[pairs[i]] = i;
    }

    vector<vector<P>> g(sz);
    //駅での乗り換え
    rep(i, sz) {
        if(pairs[i].sc == -1) continue;
        int station = pairs[i].fr;
        int out = mp[P(station, -1)];
        g[i].pb(P(out, 0));
        g[out].pb(P(i, 1)); //別に余分に辺を張る分には構わない
    }
    //路線間の移動
    rep(i, m) {
        int s = mp[P(p[i], c[i])], t = mp[P(q[i], c[i])];
        g[s].pb(P(t, 0));
        g[t].pb(P(s, 0));
    }
    int start = mp[P(0, -1)], goal = mp[P(n - 1, -1)];
    vector<int> dist(sz, -1);
    deque<int> deq;
    deq.push_back(start);
    dist[start] = 0;
    while(deq.size()) {
        int x = deq.front(); deq.pop_front();
        for(auto& y: g[x]) {
            int to = y.fr, cost = y.sc;
            if(dist[to] == -1) {
                if(cost == 0) {
                    dist[to] = dist[x];
                    deq.push_front(to);
                } else {
                    dist[to] = dist[x] + 1;
                    deq.push_back(to);
                }
            }
        }
    }
    cout << dist[goal] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:60:16: error: 'p' was not declared in this scope
   60 |         cin >> p[i] >> q[i] >> c[i];
      |                ^
a.cc:60:24: error: 'q' was not declared in this scope
   60 |         cin >> p[i] >> q[i] >> c[i];
      |                        ^
a.cc:60:32: error: 'c' was not declared in this scope
   60 |         cin >> p[i] >> q[i] >> c[i];
      |                                ^
a.cc:85:22: error: 'p' was not declared in this scope
   85 |         int s = mp[P(p[i], c[i])], t = mp[P(q[i], c[i])];
      |                      ^
a.cc:85:28: error: 'c' was not declared in this scope
   85 |         int s = mp[P(p[i], c[i])], t = mp[P(q[i], c[i])];
      |                            ^
a.cc:86:19: error: 't' was not declared in this scope
   86 |         g[s].pb(P(t, 0));
      |                   ^