Problem p00303 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

void stronglyConnectedComponents(const vector<vector<int>> &edges,
                                 vector<int> &indexConvert,
                                 vector<vector<int>> &nodesOut) {
  const int n = edges.size();
  vector<int> num(n, -1), low(n, -1);
  vector<bool> isStk(n, false);
  stack<int> stk;
  int cnt = -1;
  nodesOut.clear();

  for (int i = 0; i < n; ++i) {
    stack<pair<int, unsigned>> arg;
    arg.push(make_pair(i, 0));

    while (!arg.empty()) {
      int v = arg.top().first;
      unsigned j = arg.top().second;
      arg.pop();

      if (j == 0) {
        if (num[v] != -1)
          continue;
        num[v] = low[v] = ++cnt;
        stk.push(v);
        isStk[v] = true;
      } else {
        int w = edges[v][j - 1];
        if (isStk[w])
          low[v] = min(low[v], low[w]);
      }

      if (j < edges[v].size()) {
        arg.push(make_pair(v, j + 1));
        int w = edges[v][j];
        arg.push(make_pair(w, 0));
      } else if (low[v] == num[v]) {
        nodesOut.push_back(vector<int>());
        for (;;) {
          int w = stk.top();
          stk.pop();
          isStk[w] = false;
          nodesOut.back().push_back(w);
          if (v == w)
            break;
        }
      }
    }
  }

  reverse(nodesOut.begin(),
          nodesOut.end()); // DAG???????????????????????¢?????????
  const int m = nodesOut.size();
  indexConvert.resize(n);
  for (int i = 0; i < m; ++i) {
    for (unsigned j = 0; j < nodesOut[i].size(); ++j)
      indexConvert[nodesOut[i][j]] = i;
  }
}

int main() {
  int n;
  cin >> n;

  vector<vector<int>> edges(200);
  for (int i = 0; i < n; ++i) {
    int u, d;
    string s;
    cin >> u >> s >> d;
    if (s == "wait")
      edges[u].push_back(d + 100);
    else
      edges[d + 100].push_back(u);
  }

  vector<int> indexConvert;
  vector<vector<int>> nodesOut;
  stronglyConnectedComponents(edges, indexConvert, nodesOut);
  if (nodesOut.size() == 200)
    cout << 0 << endl;
  else
    cout << 1 << endl;

  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

void stronglyConnectedComponents(const vector<vector<int>> &edges,
                                 vector<int> &indexConvert,
                                 vector<vector<int>> &nodesOut) {
  const int n = edges.size();
  vector<int> num(n, -1), low(n, -1);
  vector<bool> isStk(n, false);
  stack<int> stk;
  int cnt = -1;
  nodesOut.clear();

  for (int i = 0; i < n; ++i) {
    stack<pair<int, unsigned>> arg;
    arg.push(make_pair(i, 0));

    while (!arg.empty()) {
      int v = arg.top().first;
      unsigned j = arg.top().second;
      arg.pop();

      if (j == 0) {
        if (num[v] != -1)
          continue;
        num[v] = low[v] = ++cnt;
        stk.push(v);
        isStk[v] = true;
      } else {
        int w = edges[v][j - 1];
        if (isStk[w])
          low[v] = min(low[v], low[w]);
      }

      if (j < edges[v].size()) {
        arg.push(make_pair(v, j + 1));
        int w = edges[v][j];
        arg.push(make_pair(w, 0));
      } else if (low[v] == num[v]) {
        nodesOut.push_back(vector<int>());
        for (;;) {
          int w = stk.top();
          stk.pop();
          isStk[w] = false;
          nodesOut.back().push_back(w);
          if (v == w)
            break;
        }
      }
    }
  }

  reverse(nodesOut.begin(),
          nodesOut.end()); // DAG???????????????????????¢?????????
  const int m = nodesOut.size();
  indexConvert.resize(n);
  for (int i = 0; i < m; ++i) {
    for (unsigned j = 0; j < nodesOut[i].size(); ++j)
      indexConvert[nodesOut[i][j]] = i;
  }
}

int main() {
  int n;
  cin >> n;

  vector<vector<int>> edges(200);
  for (int i = 0; i < n; ++i) {
    int u, d;
    string s;
    cin >> u >> s >> d;
    --u;
    --d;
    if (s == "wait")
      edges[u].push_back(d + 100);
    else
      edges[d + 100].push_back(u);
  }

  vector<int> indexConvert;
  vector<vector<int>> nodesOut;
  stronglyConnectedComponents(edges, indexConvert, nodesOut);
  if (nodesOut.size() == 200)
    cout << 0 << endl;
  else
    cout << 1 << endl;

  return 0;
}