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

// To compile : type "$     g++ test.cpp -std=c++14 -I .    "
#include <atcoder/scc>
#include <bits/stdc++.h>
// #include <chrono>
// #pragma GCC optimize("Ofast")
using namespace std;
using namespace atcoder;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M, H, W, Q, K, A, B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL << 60);

int main() {
  cin >> N >> M;
  scc_graph G(N);
  rep(i, M) {
    int a, b;
    scanf("%d%d", &a, &b);
    G.add_edge(a, b);
  }
  auto scc_list = G.scc();
  printf("%d\\n", (int)scc_list.size());
  for (vector<int> v : scc_list) {
    int n = v.size();
    printf("%d ", n);
    rep(i, n) printf("%d%c", v[i], " \\n"[i == n - 1]);
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
// #include <chrono>
// #pragma GCC optimize("Ofast")
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M, H, W, Q, K, A, B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL << 60);
/*
void dfs1(int v, int &k, mat &G, vec &level){
    level[v] = -2;
    for(int to : G[v]){
        if(level[to] == -1) dfs1(to, k, G, level);
    }
    level[v] = k++;
}
 */

void dfs1(int n, mat &G, vec &level) {
  int k(0);
  stack<int> sta;
  rep(i, n) {
    if (level[i] != -1)
      continue;
    sta.push(i);
    while (!sta.empty()) {
      int v = sta.top();
      sta.pop();
      if (v < 0) {
        level[-v - 1] = k++;
      } else {
        level[v] = -2;
        sta.push(-v - 1);
        for (int to : G[v])
          if (level[to] == -1)
            sta.push(to);
      }
    }
  }
}

/*
void dfs2(int v, mat &G, vector<bool> &used, vec &res){
    used[v] = true;
    res.push_back(v);
    for(int to : G[v]) if(!used[to]) dfs2(to, G, used, res);
}
 */

void dfs2(int n, mat &G, vector<bool> &used, vec &ord, mat &res) {
  stack<int> sta;
  Rrep(i, n) {
    int s = ord[i];
    if (!used[s]) {
      vec temp(0);
      sta.push(s);
      while (!sta.empty()) {
        int v = sta.top();
        sta.pop();
        used[v] = true;
        temp.push_back(v);
        for (int to : G[v])
          if (!used[to])
            sta.push(to);
      }
      res.push_back(temp);
    }
  }
}

void scc(mat &G, mat &res) {
  int n = G.size();
  mat G_rev(n, vec(0));
  rep(u, n) rep(v, (int)G[u].size()) G_rev[G[u][v]].push_back(u);
  vec level(n, -1), ord(n);
  vector<bool> used(n, false);
  int k(0);
  dfs1(n, G, level);
  rep(i, n) ord[level[i]] = i;
  dfs2(n, G_rev, used, ord, res);
}

int main() {
  cin >> N >> M;
  mat G(N, vec(0));
  vec num_in(N, 0);
  rep(i, M) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
  }
  mat scc_list(0);
  scc(G, scc_list);
  printf("%d\\n", (int)scc_list.size());
  for (vec v : scc_list) {
    int n = v.size();
    printf("%d ", n);
    rep(i, n) printf("%lld%c", v[i], " \\n"[i == n - 1]);
  }
}