Problem p04003 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define fastInp                                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 2 * 1e5 + 10, MOD = 1e9 + 7, INF = 1e9;

vector<vector<pair<ll, ll>>> graph, nw;
map<pair<ll, ll>, ll> ch;
map<ll, ll> rv;
vector<vector<ll>> cols;
ll dist[SIZE];

int main() {
  fastInp;

  ll n, m;
  cin >> n >> m;

  cols.resize(n);
  graph.resize(n);
  for (int i = 0; i < m; i++) {
    ll u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    cols[u].push_back(c);
    cols[v].push_back(c);
    graph[v].push_back({u, c});
    graph[u].push_back({v, c});
  }

  ll lst = -1;
  nw.resize((n + m) * 2);
  for (int i = 0; i < n; i++) {
    lst++;
    ch[{i, -1}] = lst;
    ll v = lst;
    for (auto cur : cols[i]) {
      lst++;
      ch[{i, cur}] = lst;
      nw[v].push_back({lst, 1});
      nw[lst].push_back({v, 1});
    }
  }

  for (int i = 0; i < n; i++) {
    for (auto cur : graph[i]) {
      ll k = ch[{i, cur.second}], k2 = ch[{cur.first, cur.second}];
      nw[ch[{i, cur.second}]].push_back({ch[{cur.first, cur.second}], 0});
    }
  }

  queue<ll> q;
  q.push(0);
  for (int i = 1; i <= lst; i++)
    dist[i] = INF;

  while (!q.empty()) {
    ll v = q.front();
    q.pop();
    for (auto to : nw[v]) {
      if (dist[to.first] > dist[v] + to.second) {
        q.push(to.first);
        dist[to.first] = dist[v] + to.second;
      }
    }
  }

  if (dist[ch[{n - 1, -1}]] == INF) {
    cout << "-1";
    return 0;
  }
  cout << dist[ch[{n - 1, -1}]] / 2;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define fastInp                                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 2 * 1e6 + 10, MOD = 1e9 + 7, INF = 1e9;

vector<vector<pair<ll, ll>>> graph, nw;
map<pair<ll, ll>, ll> ch;
map<ll, ll> rv;
vector<vector<ll>> cols;
ll dist[SIZE];

int main() {
  fastInp;

  ll n, m;
  cin >> n >> m;

  cols.resize(n);
  graph.resize(n);
  for (int i = 0; i < m; i++) {
    ll u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    cols[u].push_back(c);
    cols[v].push_back(c);
    graph[v].push_back({u, c});
    graph[u].push_back({v, c});
  }

  ll lst = -1;
  nw.resize((n + m) * 2);
  for (int i = 0; i < n; i++) {
    lst++;
    ch[{i, -1}] = lst;
    ll v = lst;
    for (auto cur : cols[i]) {
      lst++;
      ch[{i, cur}] = lst;
      nw[v].push_back({lst, 1});
      nw[lst].push_back({v, 1});
    }
  }

  for (int i = 0; i < n; i++) {
    for (auto cur : graph[i]) {
      ll k = ch[{i, cur.second}], k2 = ch[{cur.first, cur.second}];
      nw[ch[{i, cur.second}]].push_back({ch[{cur.first, cur.second}], 0});
    }
  }

  queue<ll> q;
  q.push(0);
  for (int i = 1; i <= lst; i++)
    dist[i] = INF;

  while (!q.empty()) {
    ll v = q.front();
    q.pop();
    for (auto to : nw[v]) {
      if (dist[to.first] > dist[v] + to.second) {
        q.push(to.first);
        dist[to.first] = dist[v] + to.second;
      }
    }
  }

  if (dist[ch[{n - 1, -1}]] == INF) {
    cout << "-1";
    return 0;
  }
  cout << dist[ch[{n - 1, -1}]] / 2;
  return 0;
}