Problem p00550 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
vector<int> x[1 << 17], d[1 << 17];
int a[1 << 18], b[1 << 18], ret[1 << 17], ans[1 << 18], n, m, q, dist[1 << 17];
vector<pair<int, int>> y[1 << 17];
map<pair<int, int>, int> M;
int main() {
  cin >> n >> m >> q;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    x[a[i]].push_back(b[i]);
    x[b[i]].push_back(a[i]);
  }
  for (int i = 1; i <= q; i++) {
    int c;
    cin >> c;
    M[make_pair(a[c], b[c])] = i;
    M[make_pair(b[c], a[c])] = i;
  }
  queue<int> Q;
  Q.push(1);
  for (int i = 1; i <= n; i++)
    dist[i] = (1 << 25);
  dist[1] = 0;
  while (!Q.empty()) {
    int a1 = Q.front();
    Q.pop();
    for (int j = 0; j < (int)x[a1].size(); j++) {
      int i = x[a1][j];
      if (dist[i] > dist[a1] + 1) {
        dist[i] = dist[a1] + 1;
        Q.push(i);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    d[dist[i]].push_back(i);
    for (int k = 0; k < (int)x[i].size(); k++) {
      int j = x[i][k];
      if (dist[i] > dist[j]) {
        y[i].push_back(make_pair(j, M[make_pair(i, j)]));
        // cout<<i<<' '<<j<<' '<<M[make_pair(i,j)]<<endl;
      }
    }
  }
  ret[1] = 1 << 30;
  for (int h = 1; h <= n; h++) {
    for (int l = 0; l < (int)d[h].size(); l++) {
      int i = d[h][l];
      for (int k = 0; k < (int)y[i].size(); k++) {
        pair<int, int> j = y[i][k];
        int cs = j.second;
        if (cs == 0)
          cs = (1 << 30);
        ret[i] = max(ret[i], min(ret[j.first], cs));
      }
    }
  }
  // for(int i=1;i<=n;i++)cout<<ret[i]<<' '<<dist[i]<<endl;
  for (int i = 1; i <= n; i++) {
    if (ret[i] <= q)
      ans[ret[i]]++;
  }
  for (int i = 1; i <= q; i++) {
    ans[i] += ans[i - 1];
    cout << ans[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
vector<int> x[1 << 17], d[1 << 17];
int a[1 << 17], b[1 << 17], ret[1 << 17], ans[1 << 17], n, m, q, dist[1 << 17];
vector<pair<int, int>> y[1 << 17];
map<pair<int, int>, int> M;
int main() {
  cin >> n >> m >> q;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    x[a[i]].push_back(b[i]);
    x[b[i]].push_back(a[i]);
  }
  for (int i = 1; i <= q; i++) {
    int c;
    cin >> c;
    M[make_pair(a[c], b[c])] = i;
    M[make_pair(b[c], a[c])] = i;
  }
  queue<int> Q;
  Q.push(1);
  for (int i = 1; i <= n; i++)
    dist[i] = (1 << 25);
  dist[1] = 0;
  while (!Q.empty()) {
    int a1 = Q.front();
    Q.pop();
    for (int j = 0; j < (int)x[a1].size(); j++) {
      int i = x[a1][j];
      if (dist[i] > dist[a1] + 1) {
        dist[i] = dist[a1] + 1;
        Q.push(i);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    d[dist[i]].push_back(i);
    for (int k = 0; k < (int)x[i].size(); k++) {
      int j = x[i][k];
      if (dist[i] > dist[j]) {
        y[i].push_back(make_pair(j, M[make_pair(i, j)]));
        // cout<<i<<' '<<j<<' '<<M[make_pair(i,j)]<<endl;
      }
    }
  }
  ret[1] = 1 << 30;
  for (int h = 1; h <= n; h++) {
    for (int l = 0; l < (int)d[h].size(); l++) {
      int i = d[h][l];
      for (int k = 0; k < (int)y[i].size(); k++) {
        pair<int, int> j = y[i][k];
        int cs = j.second;
        if (cs == 0)
          cs = (1 << 30);
        ret[i] = max(ret[i], min(ret[j.first], cs));
      }
    }
  }
  // for(int i=1;i<=n;i++)cout<<ret[i]<<' '<<dist[i]<<endl;
  for (int i = 1; i <= n; i++) {
    if (ret[i] <= q)
      ans[ret[i]]++;
  }
  for (int i = 1; i <= q; i++) {
    ans[i] += ans[i - 1];
    cout << ans[i] << endl;
  }
  return 0;
}