Language: C++

#include<bits/stdc++.h>
using namespace std;
using int = int64_t;
using P = pair<int, int>;

const int INF = 1e9;

template<typename T>
class Dijk{
    private:
        int n;
        vector<vector<pair<int, T>>> v;
    public:
        T INF;
        
        Dijk(const vector<vector<pair<int, T>>> &v, T INF){
            this->n = v.size();
            this->v = v;
            this->INF = INF;
        }
        
        vector<int> dijk(int start){
            vector<int> d(n, INF);
            d[start] = 0;
            priority_queue<pair<int, T>, vector<pair<int, T>>, function<bool(pair<int, T>, pair<int, T>)>> q([&](pair<int, T> a, pair<int, T> b){return a.second > b.second;});
            q.push(pair<int, T>(start, 0));
            while(q.size()){
                pair<int, T> now = q.top();
                q.pop();
                if(d[now.first] < now.second){
                    continue;
                }
                for(auto next : v[now.first]){
                    if(d[next.first] == INF || d[now.first] + next.second < d[next.first]){
                        d[next.first] = d[now.first] + next.second;
                        q.push(pair<int, T>(next.first, d[now.first] + next.second));
                    }
                }
            }
            return d;
        }
};

vector<vector<P>> edges;
vector<P> idv = {P(-1, -1)};

int get_id(int n, int c){
    auto ite = lower_bound(idv.begin(), idv.end(), P(n, c));
    return ite - idv.begin();
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<P, int>> etmp;
    vector<vector<int>> company(N);

    for(int i = 0; i < M; i++){
        int p, q, c;
        cin >> p >> q >> c;
        p--;
        q--;
        c--;
        company[p].push_back(c);
        company[q].push_back(c);
        etmp.push_back(make_pair(P(p, q), c));
    }

    for(int i = 0; i < N; i++){
        auto &v = company[i];
        sort(v.begin(), v.end());
        auto ite = unique(v.begin(), v.end());
        v.erase(ite, v.end());
        for(int c : v) idv.push_back(P(i, c));
    }

    edges.resize(idv.size());
    for(int c : company[0]){
        int id = get_id(0, c);
        edges[0].push_back(P(id, 1));
        edges[id].push_back(P(0, 1));
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < company[i].size(); j++){
            for(int k = j + 1; k < company[i].size(); k++){
                int id1 = get_id(i, company[i][j]);
                int id2 = get_id(i, company[i][k]);
                edges[id1].push_back(P(id2, 1));
                edges[id2].push_back(P(id1, 1));
            }
        }
    }
    for(const auto &e : etmp){
        int n1, n2;
        tie(n1, n2) = e.first;
        int id1 = get_id(n1, e.second);
        int id2 = get_id(n2, e.second);
        edges[id1].push_back(P(id2, 0));
        edges[id2].push_back(P(id1, 0));
    }

    Dijk<int> dijk(edges, INF);
    const auto dist = move(dijk.dijk(0));
    int ans = INF;
    for(int c : company[N - 1]){
        int id = get_id(N - 1, c);
        ans = min(ans, dist[id]);
    }
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc:3:7: error: expected nested-name-specifier before 'int'
    3 | using int = int64_t;
      |       ^~~