Language: C++

#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
 
//int dxy[5] = {0, 1, 0, -1, 0};
// // assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder lcm vi st gin
 
typedef int Weight;
typedef int Flow;
struct Edge {
    int s, d; Weight w; Flow c;
    Edge() {};
    Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }
 
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
 
void addArc(Graph &g, int s, int d, int w = 1) {
    g[s].push_back(Edge(s, d, w));
}
void addEdge(Graph &g, int a, int b, int w = 1) {
    addArc(g, a, b, w);
    addArc(g, b, a, w);
}
 
Graph g;
 
//単一始点最短経路(負閉路なし)
//Dijkstra O((|E|+|V|)log|V|)
//dist: 始点から各頂点までの最短距離, assignされるので安心して欲しい
//戻り値: 最短経路木の親頂点(根は-1)
vector<int> dijkstra(const Graph &g, int s, Array &dist) {
    int n = g.size();
    assert(s < n);
    enum { WHITE, GRAY, BLACK };
    vector<int> color(n, WHITE); color[s] = GRAY;
    vector<int> prev(n, -1);
    dist.assign(n, INF); dist[s] = 0;
    //始点からの最短距離 子 親
    typedef pair< int, pair < int, int > > State;
    priority_queue<State, vector<State>, greater<State> > pq;
    pq.push(State(0, i_i(s, -1)));
    while (pq.size()) {
        Weight d = pq.top().first; 
        int v = pq.top().second.first, u = pq.top().second.second; 
        pq.pop();
        if (dist[v] < d)continue;
        color[v] = BLACK; prev[v] = u;
        for (int i = 0; i < g[v].size(); i++) {
            Edge e = g[v][i];
            if (color[e.d] == BLACK)continue;
            if (dist[e.d] > dist[v] + e.w) {
                dist[e.d] = dist[v] + e.w;
                pq.push(State(dist[e.d], i_i(e.d, v)));
                color[e.d] = GRAY;
            }
        }
    }
    return prev;
}
 
map<i_i, int> id;
int ptr;
 
int getid(int a, int b)
{
    if (id.find(i_i(a, b)) == id.end()) {
        id.insert(mp(i_i(a, b), ptr));
        g.pb(Edges());
        return ptr++;
    } else {
        return id[i_i(a, b)];
    }
}
 
signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
 
    int2(n, m);
    if (!m) {
        if (n == 1) cout << 0 << endl;
        else cout << -1 << endl;
        return 0;
    }
    vvi ec(n);
    for (int i = 0; i < m; i++) {
        int tmpx, tmpy, color;
        cin >> tmpx >> tmpy >> color;
        tmpx--; tmpy--;
        ec[tmpx].pb(color);
        ec[tmpy].pb(color);
        int a = getid(tmpx, color), b = getid(tmpy, color);
        addEdge(g, a, b, 0);
    }
    rep(i, n) {
        for (int j : ec[i]) {
            int from = getid(i, j), to = getid(i, -1);
            addArc(g, from, to, 0);
            addArc(g, to, from, 1);
        }
    }
    //cout << g.size() << endl;
    vi dist;
    dijkstra(g, getid(0, -1), dist);
    int tmp = getid(n-1, -1);
  	if (tmp >= dist.size()) {
      cout << -1 << endl;
      return 0;
    }
    if (dist[getid(n-1, -1)] == INF) cout << -1 << endl;
    else cout << dist[getid(n-1, -1)] << endl;
 
    return 0;
}

Compiler output:
a.cc:2:1: error: extended character   is not valid in an identifier
    2 |  
      | ^
a.cc:4:1: error: extended character   is not valid in an identifier
    4 |  
      | ^
a.cc:31:1: error: extended character   is not valid in an identifier
   31 |  
      | ^
a.cc:35:1: error: extended character   is not valid in an identifier
   35 |  
      | ^
a.cc:46:1: error: extended character   is not valid in an identifier
   46 |  
      | ^
a.cc:51:1: error: extended character   is not valid in an identifier
   51 |  
      | ^
a.cc:59:1: error: extended character   is not valid in an identifier
   59 |  
      | ^
a.cc:61:1: error: extended character   is not valid in an identifier
   61 |  
      | ^
a.cc:95:1: error: extended character   is not valid in an identifier
   95 |  
      | ^
a.cc:98:1: error: extended character   is not valid in an identifier
   98 |  
      | ^
a.cc:109:1: error: extended character   is not valid in an identifier
  109 |  
      | ^
a.cc:114:1: error: extended character   is not valid in an identifier
  114 |  
      | ^
a.cc:148:1: error: extended character   is not valid in an identifier
  148 |  
      | ^
a.cc:2:1: error: '\U000000a0' does not name a type
    2 |  
      | ^
a.cc:4:1: error: '\U000000a0' does not name a type
    4 |  
      | ^
a.cc:39:15: error: 'Weight' does not name a type
   39 |     int s, d; Weight w; Flow c;
      |               ^~~~~~
a.cc:41:24: error: 'Weight' has not been declared
   41 |     Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
      |                        ^~~~~~
a.cc: In constructor 'Edge::Edge(long long int, long long int, int)':
a.cc:41:52: error: class 'Edge' does not have any field named 'w'
   41 |     Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
      |                                                    ^
a.cc: In function 'bool operator<(const Edge&, const Edge&)':
a.cc:43:60: error: 'const struct Edge' has no member named 'w'
   43 | bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
      |                                                            ^
a.cc:43:67: error: 'const struct Edge' has no member named 'w'
   43 | bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
      |                                                                   ^
a.cc: At global scope:
a.cc:45:8: error: 'ostream' does not name a type
   45 | inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }
      |        ^~~~~~~
a.cc:46:1: error: '\U000000a0' does not name a type
   46 |  
      | ^
a.cc:48:9: error: 'vector' does not name a type
   48 | typedef vector<Edges> Graph;
      |         ^~~~~~
a.cc:49:9: error: 'vector' does not name a type
   49 | typedef vector<Weight> Array;
      |         ^~~~~~
a.cc:50:9: error: 'vector' does not name a type
   50 | typedef vector<Array> Matrix;
      |         ^~~~~~
a.cc:51:1: error: '\U000000a0' does not name a type
   51 |  
      | ^
a.cc:55:6: error: variable or field 'addEdge' declared void
   55 | void addEdge(Graph &g, int a, int b, int w = 1) {
      |      ^~~~~~~
a.cc:55:14: error: 'Graph' was not declared in this scope; did you mean 'isgraph'?
   55 | void addEdge(Graph &g, int a, int b, int w = 1) {
      |              ^~~~~
      |              isgraph
a.cc:55:21: error: 'g' was not declared in this scope
   55 | void addEdge(Graph &g, int a, int b, int w = 1) {
      |                     ^
a.cc:8:13: error: expected primary-expression before 'long'
    8 | #define int long long
      |             ^~~~
a.cc:55:24: note: in expansion of macro 'int'
   55 | void addEdge(Graph &g, int a, int b, int w = 1) {
      |                        ^~~
a.cc:8:13: error: expected primary-expression before 'long'
    8 | #define int long long
      |             ^~~~
a.cc:55:31: note: in expansion of macro 'int'
   55 | void addEdge(Graph &g, int a, int b, int w = 1) {
      |                               ^~~
a.cc:8:13: error: expected primary-expression before 'long'
    8 | #define int long long
      |             ^~~~
a.cc:55:38: note: in expansion of macro 'int'
   55 | void addEdge(Graph &g, int a, int b, int w = 1) {
      |                                      ^~~
a.cc:59:1: error: '\U000000a0' does not name a type
   59 |  
      | ^
a.cc:61:1: error: '\U000000a0' does not name a type
   61 |  
      | ^
a.cc:95:1: error: '\U000000a0' does not name a type
   95 |  
      | ^
a.cc:98:1: error: '\U000000a0' does not name a type
   98 |  
      | ^
a.cc:109:1: error: '\U000000a0' does not name a type
  109 |  
      | ^