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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)

class SCC_BI {
public:
  int NV = 0, time;
  vector<vector<int>> E;
  vector<int> ord, llink, inin;
  stack<int> roots, S;
  vector<int> M;             // point to group
  vector<int> ART;           // out
  vector<vector<int>> SC;    // out
  vector<pair<int, int>> BR; // out

  void init(int NV) {
    this->NV = NV;
    E.clear();
    E.resize(NV);
  }
  void add_edge(int x, int y) {
    assert(NV);
    E[x].push_back(y);
    E[y].push_back(x);
  }
  void dfs(int cur, int pre) {
    int art = 0, conn = 0, i, se = 0;
    ord[cur] = llink[cur] = ++time;
    S.push(cur);
    inin[cur] = 1;
    roots.push(cur);
    rep(i, 0, E[cur].size()) {
      int tar = E[cur][i];
      if (ord[tar] == 0) {
        conn++;
        dfs(tar, cur);
        llink[cur] = min(llink[cur], llink[tar]);
        art += (pre != -1 && ord[cur] <= llink[tar]);
        if (ord[cur] < llink[tar])
          BR.push_back(make_pair(min(cur, tar), max(cur, tar)));
      } else if (tar != pre || se) {
        llink[cur] = min(llink[cur], ord[tar]);
        while (inin[tar] && ord[roots.top()] > ord[tar])
          roots.pop();
      } else
        se++; // double edge
    }

    if (cur == roots.top()) {
      SC.push_back(vector<int>());
      while (1) {
        i = S.top();
        S.pop();
        inin[i] = 0;
        SC.back().push_back(i);
        M[i] = SC.size() - 1;
        if (i == cur)
          break;
      }
      sort(SC.back().begin(), SC.back().end());
      roots.pop();
    }
    if (art || (pre == -1 && conn > 1))
      ART.push_back(cur);
  }
  void scc() {
    SC.clear(), BR.clear(), ART.clear(), M.resize(NV);
    ord.clear(), llink.clear(), inin.clear(), time = 0;
    ord.resize(NV);
    llink.resize(NV);
    inin.resize(NV);
    for (int i = 0; i < NV; i++)
      if (!ord[i])
        dfs(i, -1);
    sort(BR.begin(), BR.end());
    sort(ART.begin(), ART.end());
  }
};
//-----------------------------------------------------------------------------------
int VV, EE;
SCC_BI g;
//-----------------------------------------------------------------------------------
int main() {
  cin >> VV >> EE;

  g.init(VV);
  rep(i, 0, EE) {
    int a, b;
    scanf("%d %d", &a, &b);
    g.add_edge(a, b);
  }
  g.scc();

  for (int a : g.ART)
    printf("%d\\n", a);
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)

class SCC_BI {
public:
  int NV = 0, time;
  vector<vector<int>> E;
  vector<int> ord, llink, inin;
  stack<int> roots, S;
  vector<int> M;             // point to group
  vector<int> ART;           // out
  vector<vector<int>> SC;    // out
  vector<pair<int, int>> BR; // out

  void init(int NV) {
    this->NV = NV;
    E.clear();
    E.resize(NV);
  }
  void add_edge(int x, int y) {
    assert(NV);
    E[x].push_back(y);
    E[y].push_back(x);
  }
  void dfs(int cur, int pre) {
    int art = 0, conn = 0, i, se = 0;
    ord[cur] = llink[cur] = ++time;
    S.push(cur);
    inin[cur] = 1;
    roots.push(cur);
    rep(i, 0, E[cur].size()) {
      int tar = E[cur][i];
      if (ord[tar] == 0) {
        conn++;
        dfs(tar, cur);
        llink[cur] = min(llink[cur], llink[tar]);
        art += (pre != -1 && ord[cur] <= llink[tar]);
        if (ord[cur] < llink[tar])
          BR.push_back(make_pair(min(cur, tar), max(cur, tar)));
      } else if (tar != pre || se) {
        llink[cur] = min(llink[cur], ord[tar]);
        while (inin[tar] && ord[roots.top()] > ord[tar])
          roots.pop();
      } else
        se++; // double edge
    }

    if (cur == roots.top()) {
      SC.push_back(vector<int>());
      while (1) {
        i = S.top();
        S.pop();
        inin[i] = 0;
        SC.back().push_back(i);
        M[i] = SC.size() - 1;
        if (i == cur)
          break;
      }
      sort(SC.back().begin(), SC.back().end());
      roots.pop();
    }
    if (art || (pre == -1 && conn > 1))
      ART.push_back(cur);
  }
  void scc() {
    SC.clear(), BR.clear(), ART.clear(), M.resize(NV);
    ord.clear(), llink.clear(), inin.clear(), time = 0;
    ord.resize(NV);
    llink.resize(NV);
    inin.resize(NV);
    for (int i = 0; i < NV; i++)
      if (!ord[i])
        dfs(i, -1);
    sort(BR.begin(), BR.end());
    sort(ART.begin(), ART.end());
  }
};
//-----------------------------------------------------------------------------------
int VV, EE;
//-----------------------------------------------------------------------------------
int main() {
  cin >> VV >> EE;
  SCC_BI g;
  g.init(VV);
  rep(i, 0, EE) {
    int a, b;
    scanf("%d %d");
    g.add_edge(a, b);
  }
  g.scc();

  // for (int a : g.ART) printf("%d\\n", a);
}