Problem p03126 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> tpl;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(c) reverse((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define RREP(i, n) RFOR(i, n, 0)

const double EPS = 1e-9;
const double PI = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL << 60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  int N, M;
  cin >> N >> M;
  VVI pref(N, VI(0, M));
  REP(i, N) {
    int k;
    cin >> k;
    REP(j, k) {
      int a;
      cin >> a;
      a--;
      pref[i][a] = 1;
    }
  }
  int ans = 0;
  REP(i, M) {
    bool flag = true;
    REP(j, N) {
      if (pref[j][i] == 0) {
        flag = false;
        break;
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> tpl;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(c) reverse((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define RREP(i, n) RFOR(i, n, 0)

const double EPS = 1e-9;
const double PI = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL << 60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  int N, M;
  cin >> N >> M;
  VVI pref(N, VI(M, 0));
  REP(i, N) {
    int k;
    cin >> k;
    REP(j, k) {
      int a;
      cin >> a;
      a--;
      pref[i][a] = 1;
    }
  }
  int ans = 0;
  REP(i, M) {
    bool flag = true;
    REP(j, N) {
      if (pref[j][i] == 0) {
        flag = false;
        break;
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;
  return 0;
}