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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
// #define int ll
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
// #define mt make_tuple
// typedef tuple<pii,int,int> tp;
// typedef vector<tp> vt;
template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
// template<class C>constexpr int size(const C &c){return (int)c.size();}
// template<class T,size_t N> constexpr int size(const T
// (&xs)[N])noexcept{return (int)N;}
const double PI = acos(-1);
const double EPS = 1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
vvi used;
vvi G;
int n, m, go[3];
void dfs(int a, int b) {
  a++;
  if (a == 110)
    return;
  rep(i, G[b].size()) {
    int to = G[b][i];
    if (used[a][to])
      continue;
    used[a][to] = true;
    dfs(a, to);
  }
}
int main() {
  cin >> n >> m >> go[0] >> go[1] >> go[2];
  G = vvi(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].pb(b);
  }
  vector<vvi> po(n, vvi(3));
  rep(i, n) {
    used = vvi(110, vi(n));
    used[0][i] = true;
    dfs(0, i);
    rep(j, 3) rep(k, n) if (used[go[j]][k]) po[i][j].pb(k);
  }
  //	rep(i,n){
  //		rep(j,3){rep(k,po[i][j].size())cout<<"
  //"<<po[i][j][k];cout<<endl;} 		cout<<endl;
  //	}
  vi ok(n);
  ok[n - 1] = true;
  rep(i, 110) {
    vi nok = ok;
    rep(j, n) if (ok[j] == 0) {
      bool H = true;
      rep(k, 3) {
        bool h = false;
        rep(l, po[j][k].size()) if (ok[po[j][k][l]]) h = true;
        if (!h)
          H = false;
      }
      //	cout<<i<<" "<<j<<" "<<H<<endl;
      if (H)
        nok[j] = true;
    }
    ok = nok;
    if (ok[0]) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
// #define int ll
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
// #define mt make_tuple
// typedef tuple<pii,int,int> tp;
// typedef vector<tp> vt;
template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
// template<class C>constexpr int size(const C &c){return (int)c.size();}
// template<class T,size_t N> constexpr int size(const T
// (&xs)[N])noexcept{return (int)N;}
const double PI = acos(-1);
const double EPS = 1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
vvi used;
vvi G;
int n, m, go[3];
void dfs(int a, int b) {
  if (a == 110)
    return;
  a++;
  rep(i, G[b].size()) {
    int to = G[b][i];
    if (used[a][to])
      continue;
    used[a][to] = true;
    dfs(a, to);
  }
}
int main() {
  cin >> n >> m >> go[0] >> go[1] >> go[2];
  G = vvi(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].pb(b);
  }
  vector<vvi> po(n, vvi(3));
  rep(i, n) {
    used = vvi(110, vi(n));
    used[0][i] = true;
    dfs(0, i);
    rep(j, 3) rep(k, n) if (used[go[j]][k]) po[i][j].pb(k);
  }
  //	rep(i,n){
  //		rep(j,3){rep(k,po[i][j].size())cout<<"
  //"<<po[i][j][k];cout<<endl;} 		cout<<endl;
  //	}
  vi ok(n);
  ok[n - 1] = true;
  rep(i, 110) {
    vi nok = ok;
    rep(j, n) if (ok[j] == 0) {
      bool H = true;
      rep(k, 3) {
        bool h = false;
        rep(l, po[j][k].size()) if (ok[po[j][k][l]]) h = true;
        if (!h)
          H = false;
      }
      //	cout<<i<<" "<<j<<" "<<H<<endl;
      if (H)
        nok[j] = true;
    }
    ok = nok;
    if (ok[0]) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}