Problem p01770 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)

using namespace std;

struct Edge {
  int src, dst, bitmask;
};
struct Data {
  int cur, weight, bitmask, step;
  bool operator<(const Data &data) const { return weight > data.weight; }
};

const int MAX_V = 101;
const int MAX_R = 101;
const int IINF = INT_MAX;
int V, E, M, S, T, R, bits[MAX_V];
vector<Edge> G[MAX_V];
int mini[MAX_V][MAX_R][1 << 4];

void compute() {
  // rep(i,V) rep(k,R+1) rep(j,(1<<4)) mini[i][k][j] = IINF;
  rep(i, MAX_V) rep(k, MAX_R) rep(j, (1 << 4)) mini[i][k][j] = IINF;
  mini[S][0][bits[S]] = 0;
  priority_queue<Data> Q;
  Q.push((Data){S, 0, bits[S], 0});
  while (!Q.empty()) {
    Data data = Q.top();
    Q.pop();
    if (data.cur == T) {
      cout << data.weight << endl;
      return;
    }
    rep(i, (int)G[data.cur].size()) {
      Edge &v = G[data.cur][i];
      if (v.bitmask != -1) {
        if ((v.bitmask & data.bitmask) == 0)
          continue;
      }
      int bitmask = data.bitmask | bits[v.dst];
      if (data.step + 1 <= R &&
          mini[v.dst][data.step + 1][bitmask] > data.weight + 1) {
        mini[v.dst][data.step + 1][bitmask] = data.weight + 1;
        Q.push((Data){v.dst, data.weight + 1, bitmask, data.step + 1});
      }
    }
    if (mini[S][0][data.bitmask] > data.weight + 1) {
      mini[S][0][data.bitmask] = data.weight + 1;
      Q.push((Data){S, data.weight + 1, data.bitmask, 0});
    }
  }
  assert(false);
}

int main() {
  cin >> V >> E >> M >> S >> T >> R;
  rep(i, E) {
    int s, t;
    cin >> s >> t;
    G[s].push_back((Edge){s, t, -1});
    G[t].push_back((Edge){t, s, -1});
  }
  rep(i, M) {
    int s, t, c;
    cin >> s >> t >> c;
    bits[c] |= (1 << i);
    G[s].push_back((Edge){s, t, (1 << i)});
    G[t].push_back((Edge){t, s, (1 << i)});
  }
  compute();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)

using namespace std;

struct Edge {
  int src, dst, bitmask;
};
struct Data {
  int cur, weight, bitmask, step;
  bool operator<(const Data &data) const { return weight > data.weight; }
};

const int MAX_V = 101;
const int MAX_R = 101;
const int IINF = INT_MAX;
int V, E, M, S, T, R, bits[MAX_V];
vector<Edge> G[MAX_V];
int mini[MAX_V][MAX_R][1 << 4];

void compute() {
  // rep(i,V) rep(k,R+1) rep(j,(1<<4)) mini[i][k][j] = IINF;
  rep(i, MAX_V) rep(k, MAX_R) rep(j, (1 << 4)) mini[i][k][j] = IINF;
  mini[S][0][bits[S]] = 0;
  priority_queue<Data> Q;
  Q.push((Data){S, 0, bits[S], 0});
  while (!Q.empty()) {
    Data data = Q.top();
    Q.pop();
    if (data.cur == T) {
      cout << data.weight << endl;
      return;
    }
    rep(i, (int)G[data.cur].size()) {
      Edge &v = G[data.cur][i];
      if (v.bitmask != -1) {
        if ((v.bitmask & data.bitmask) == 0)
          continue;
      }
      int bitmask = data.bitmask | bits[v.dst];
      if (data.step + 1 <= R &&
          mini[v.dst][data.step + 1][bitmask] > data.weight + 1) {
        mini[v.dst][data.step + 1][bitmask] = data.weight + 1;
        Q.push((Data){v.dst, data.weight + 1, bitmask, data.step + 1});
      }
    }
    if (mini[S][0][data.bitmask] > data.weight + 1) {
      mini[S][0][data.bitmask] = data.weight + 1;
      Q.push((Data){S, data.weight + 1, data.bitmask, 0});
    }
  }
  cout << -1 << endl;
}

int main() {
  cin >> V >> E >> M >> S >> T >> R;
  rep(i, E) {
    int s, t;
    cin >> s >> t;
    G[s].push_back((Edge){s, t, -1});
    G[t].push_back((Edge){t, s, -1});
  }
  rep(i, M) {
    int s, t, c;
    cin >> s >> t >> c;
    bits[c] |= (1 << i);
    G[s].push_back((Edge){s, t, (1 << i)});
    G[t].push_back((Edge){t, s, (1 << i)});
  }
  compute();
  return 0;
}