Problem p04003 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif

const int N = 200001;
struct edge {
  int to, cost;
};
vector<edge> G[N];

void dikstra(int s, int t) {
  typedef pair<int, int> P;
  const int INF = 1 << 30;

  priority_queue<P, vector<P>, greater<P>> que;
  vector<int> d(N, INF); // sからの最短距離
  d[s] = 0;
  que.push({0, s}); //{最短距離,頂点}

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (auto e : G[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push({d[e.to], e.to});
      }
    }
  }
  if (d[t] == INF)
    cout << -1 << endl;
  else
    cout << d[t] << endl;
}

using P = pair<int, int>;

signed main() {

  int n, m;
  cin >> n >> m;
  vector<int> p(m), q(m), c(m);
  vector<vector<int>> station(n);
  vector<P> v;
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> q[i] >> c[i];
    p[i]--, q[i]--, c[i]--;
    station[p[i]].push_back(c[i]);
    station[q[i]].push_back(c[i]);
    v.push_back({p[i], c[i]});
    v.push_back({q[i], c[i]});
  }

  for (int i = 0; i < n; i++) {
    v.push_back({i, -1});
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());

  map<pair<int, int>, int> mp;
  for (int i = 0; i < v.size(); i++) {
    mp[v[i]] = i;
  }

  for (int i = 0; i < n; i++) {
    for (int c : station[i]) {
      int u = mp[{i, c}];
      int v = mp[{i, -1}];
      G[v].push_back({u, 0});
      G[u].push_back({v, 1});
    }
  }

  for (int i = 0; i < m; i++) {
    int u = mp[{p[i], c[i]}];
    int v = mp[{q[i], c[i]}];
    G[u].push_back({v, 0});
    G[v].push_back({u, 0});
  }
  dikstra(mp[{0, -1}], mp[{n - 1, -1}]);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif

const int N = 200001 * 4;
struct edge {
  int to, cost;
};
vector<edge> G[N];

void dikstra(int s, int t) {
  typedef pair<int, int> P;
  const int INF = 1 << 30;

  priority_queue<P, vector<P>, greater<P>> que;
  vector<int> d(N, INF); // sからの最短距離
  d[s] = 0;
  que.push({0, s}); //{最短距離,頂点}

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (auto e : G[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push({d[e.to], e.to});
      }
    }
  }
  if (d[t] == INF)
    cout << -1 << endl;
  else
    cout << d[t] << endl;
}

using P = pair<int, int>;

signed main() {

  int n, m;
  cin >> n >> m;
  vector<int> p(m), q(m), c(m);
  vector<vector<int>> station(n);
  vector<P> v;
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> q[i] >> c[i];
    p[i]--, q[i]--, c[i]--;
    station[p[i]].push_back(c[i]);
    station[q[i]].push_back(c[i]);
    v.push_back({p[i], c[i]});
    v.push_back({q[i], c[i]});
  }

  for (int i = 0; i < n; i++) {
    v.push_back({i, -1});
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());

  map<pair<int, int>, int> mp;
  for (int i = 0; i < v.size(); i++) {
    mp[v[i]] = i;
  }

  for (int i = 0; i < n; i++) {
    for (int c : station[i]) {
      int u = mp[{i, c}];
      int v = mp[{i, -1}];
      G[v].push_back({u, 0});
      G[u].push_back({v, 1});
    }
  }

  for (int i = 0; i < m; i++) {
    int u = mp[{p[i], c[i]}];
    int v = mp[{q[i], c[i]}];
    G[u].push_back({v, 0});
    G[v].push_back({u, 0});
  }
  dikstra(mp[{0, -1}], mp[{n - 1, -1}]);

  return 0;
}