alexjercan/bugnet huggingface dataset:
Problem p01136 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

typedef long long STATES;

int main(void) {
  int n;
  while (cin >> n && n) {
    STATES goal_state = 0;
    for (int i = 0; i < n; i++)
      goal_state |= 1LL << i;

    vector<STATES> free_days(30 + 1, 0);
    for (int i = 0; i < n; i++) {
      int k;
      cin >> k;
      for (int j = 0; j < k; j++) {
        int free_day;
        cin >> free_day;
        free_days[free_day] |= 1LL << i;
      }
    }

    int answer = -1;
    vector<STATES> dp(n, 0);
    for (int i = 0; i < n; i++)
      dp[i] = 1LL << i;
    for (int i = 1; answer == -1 && i <= 30; i++) {
      STATES next = 0;
      for (int j = 0; j < n; j++)
        if (free_days[i] & (1LL << j))
          next |= dp[j];
      for (int j = 0; j < n; j++)
        if (free_days[i] & (1LL << j))
          dp[j] |= next;
      if (next == goal_state)
        answer = i;
    }

    cout << answer << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

int n, answer;
VI states;
VVI graph;

bool is_goal() {
  for (VI::iterator it = states.begin(); it != states.end(); it++) {
    if (*it == 0)
      return false;
  }
  return true;
}

void dfs(int now, int good) {
  states[now] = 1;
  if (is_goal()) {
    if (answer == -1 || good < answer)
      answer = good;
  } else {
    for (int i = 0; i < n; i++) {
      if (states[i] == 0 && graph[now][i] != -1) {
        if (good == -1)
          dfs(i, graph[now][i]);
        else
          dfs(i, max(good, graph[now][i]));
      }
    }
  }
  states[now] = 0;
}

int main(void) {
  while (cin >> n && n) {
    answer = -1;
    states = VI(n, 0);

    VVI corresponds(30 + 1);
    for (int i = 0; i < n; i++) {
      int k;
      cin >> k;
      for (int j = 0; j < k; j++) {
        int free_day;
        cin >> free_day;
        corresponds[free_day].push_back(i);
      }
    }

    graph = VVI(n, VI(n, -1));
    for (int i = 1; i <= 30; i++) {
      for (VI::iterator it_i = corresponds[i].begin();
           it_i != corresponds[i].end(); it_i++) {
        for (VI::iterator it_j = corresponds[i].begin();
             it_j != corresponds[i].end(); it_j++) {
          if (it_i == it_j)
            continue;
          graph[*it_i][*it_j] = i;
          graph[*it_j][*it_i] = i;
        }
      }
    }

    dfs(0, -1);

    cout << answer << endl;
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

vector<int> v[31];
ll dp[31][50];
int main() {
  int n;
  while (scanf("%d", &n), n) {
    rep(i, 31) v[i].clear();
    rep(i, n) {
      int f;
      scanf("%d", &f);
      rep(j, f) {
        int k;
        scanf("%d", &k);
        v[k].push_back(i);
      }
    }
    rep(i, n) dp[0][i] = 1LL << i;
    for (int i = 1; i <= 30; i++) {
      rep(j, n) dp[i][j] = dp[i - 1][j];
      rep(t, n) for (int j : v[i]) for (int k : v[i]) {
        dp[i][j] |= dp[i][k];
        dp[i][k] |= dp[i][j];
      }
    }
    rep(i, 31) rep(j, n) {
      if (dp[i][j] == (1LL << n) - 1) {
        printf("%d\\n", i);
        goto g;
      }
    }
    puts("-1");
  g:;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

vector<int> v[31];
ll dp[31][50];
int main() {
  int n;
  while (scanf("%d", &n), n) {
    rep(i, n) {
      int f;
      scanf("%d", &f);
      rep(j, f) {
        int k;
        scanf("%d", &k);
        v[k].push_back(i);
      }
    }
    rep(i, n) dp[0][i] = 1LL << i;
    for (int i = 1; i <= 30; i++) {
      rep(j, n) dp[i][j] = dp[i - 1][j];
      rep(t, n) for (int j : v[i]) for (int k : v[i]) {
        dp[i][j] |= dp[i][k];
        dp[i][k] |= dp[i][j];
      }
    }
    rep(i, 31) rep(j, n) {
      if (dp[i][j] == (1LL << n) - 1) {
        printf("%d\\n", i);
        goto g;
      }
    }
    puts("-1");
  g:;
  }
}
Problem p01136 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main(void) {
  long long OK;
  bool T[50][30];
  vector<int> V[30];
  long long A[50];
  int n;
  while (cin >> n, n) {
    OK = 1;
    OK = (OK << n) - 1;
    fill(A, A + 50, 1);
    for (int i = 0; i < 30; ++i)
      V[i].clear();
    for (int i = 0; i < n; ++i) {
      A[i] = A[i] << i;
      // cout << A[i] << endl;
      fill(T[i], T[i] + 30, false);
      int f;
      cin >> f;
      for (int j = 0; j < f; ++j) {
        int d;
        cin >> d;
        T[i][d - 1] = true;
        V[d - 1].push_back(i);
      }
    }
    // cout << OK << endl;
    int ans = -1;
    for (int i = 0; i < 30; ++i) {
      long long check = 0;
      for (int j = 0; j < n; ++j) {
        if (T[j][i]) {
          for (int k = 0; k < V[i].size(); ++k) {
            // A[j] |= (1 << V[i][k]);
            A[j] |= A[V[i][k]];
          }
          check |= A[j];
        }
      }
      // cout << check << endl;
      if (check == OK) {
        ans = i + 1;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main(void) {
  bool T[50][30];
  vector<int> V[30];
  int n;
  while (cin >> n, n) {
    for (int i = 0; i < 30; ++i)
      V[i].clear();
    for (int i = 0; i < n; ++i) {
      fill(T[i], T[i] + 30, false);
      int f;
      cin >> f;
      for (int j = 0; j < f; ++j) {
        int d;
        cin >> d;
        T[i][d - 1] = true;
        V[d - 1].push_back(i);
      }
    }
    int ans = -1;
    bool hit = false;
    set<int> S[30];
    for (int i = 0; i < 30 && !hit; ++i) {
      for (int j = 0; j < n && !hit; ++j) {
        if (T[j][i]) {
          for (int k = 0; k < V[i].size(); ++k) {
            S[k].insert(j);
            if (S[k].size() == n) {
              ans = i + 1;
              hit = true;
              break;
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    bool f[50][50] = {false};
    vector<int> day[30];
    for (int i = 0; i < n; i++)
      f[i][i] = true;
    for (int i = 0, a; i < n; i++) {
      cin >> a;
      for (int j = 0, b; j < a; j++) {
        cin >> b;
        day[b - 1].push_back(i);
      }
    }
    for (int i = 0; i < 30; i++) {
      for (int j = 0; j < day[i].size(); j++)
        for (int k = 0; k < day[i].size(); k++)
          for (int l = 0; l < n; l++)
            f[day[i][j]][l] = f[day[i][k]][l] =
                f[day[i][j]][l] | f[day[i][k]][l];
      for (int j = 0; j < n; j++) {
        bool flag = true;
        for (int k = 0; k < n; k++)
          flag &= f[j][k];
        if (flag) {
          cout << i + 1 << endl;
          goto jump;
        }
      }
    }
    cout << "-1" << endl;
  jump:;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    bool f[50][50] = {false};
    vector<int> day[30];
    for (int i = 0; i < n; i++)
      f[i][i] = true;
    for (int i = 0, a; i < n; i++) {
      cin >> a;
      for (int j = 0, b; j < a; j++) {
        cin >> b;
        day[b - 1].push_back(i);
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < day[i].size(); j++)
        for (int k = 0; k < day[i].size(); k++)
          for (int l = 0; l < n; l++)
            f[day[i][j]][l] = f[day[i][k]][l] =
                f[day[i][j]][l] | f[day[i][k]][l];
      for (int j = 0; j < n; j++) {
        bool flag = true;
        for (int k = 0; k < n; k++)
          flag &= f[j][k];
        if (flag) {
          cout << i + 1 << endl;
          goto jump;
        }
      }
    }
    cout << "-1" << endl;
  jump:;
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int n, p, r[50], d[50][50];
bool a[50][30];
int main() {
  while (true) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      scanf("%d", &r[i]);
      for (int j = 0; j < 30; j++) {
        a[i][j] = false;
      }
      for (int j = 0; j < r[i]; j++) {
        scanf("%d", &p);
        a[i][p - 1] = true;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = 9999999;
      }
    }
    for (int i = 0; i < n; i++) {
      priority_queue<pair<int, int>> que;
      que.push(make_pair(0, i));
      d[i][i] = 0;
      while (!que.empty()) {
        pair<int, int> state = que.top();
        que.pop();
        int dist = -state.first;
        int node = state.second;
        for (int j = 0; j < n; j++) {
          for (int k = dist; k < 30; k++) {
            if (a[node][k] && a[j][k]) {
              if (d[i][j] > k) {
                d[i][j] = k;
                que.push(make_pair(-k, j));
              }
            }
          }
        }
      }
    }
    int ret = 9999999;
    for (int i = 0; i < n; i++) {
      int res = 0;
      for (int j = 0; j < n; j++) {
        res = max(res, d[j][i]);
      }
      ret = min(ret, res);
    }
    printf("%d\\n", ret == 9999999 ? -1 : ret + 1);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int n, p, r[50], d[50][50];
bool a[50][30];
int main() {
  while (true) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%d", &r[i]);
      for (int j = 0; j < 30; j++) {
        a[i][j] = false;
      }
      for (int j = 0; j < r[i]; j++) {
        scanf("%d", &p);
        a[i][p - 1] = true;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = 9999999;
      }
    }
    for (int i = 0; i < n; i++) {
      priority_queue<pair<int, int>> que;
      que.push(make_pair(0, i));
      d[i][i] = 0;
      while (!que.empty()) {
        pair<int, int> state = que.top();
        que.pop();
        int dist = -state.first;
        int node = state.second;
        for (int j = 0; j < n; j++) {
          for (int k = dist; k < 30; k++) {
            if (a[node][k] && a[j][k]) {
              if (d[i][j] > k) {
                d[i][j] = k;
                que.push(make_pair(-k, j));
              }
            }
          }
        }
      }
    }
    int ret = 9999999;
    for (int i = 0; i < n; i++) {
      int res = 0;
      for (int j = 0; j < n; j++) {
        res = max(res, d[j][i]);
      }
      ret = min(ret, res);
    }
    printf("%d\\n", ret == 9999999 ? -1 : ret);
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Runtime Error

// 09
#include <iostream>

using namespace std;

int main() {
  for (int n; cin >> n, n;) {
    bool f[50][31] = {{}};
    for (int i = 0; i < n; i++) {
      int nf;
      cin >> nf;
      while (nf--) {
        int d;
        cin >> d;
        f[i][d] = true;
      }
    }
    long long m[50];
    for (int i = 0; i < n; i++) {
      m[i] = 1LL << i;
    }
    int i;
    for (i = 1; i <= 30; i++) {
      long long cm = 0;
      for (int j = 0; j < n; j++) {
        if (f[j][i]) {
          cm |= m[j];
        }
      }
      if (cm == (1LL << n) - 1)
        break;
      for (int j = 0; j < n; j++) {
        if (f[j][i]) {
          m[j] = cm;
        }
      }
    }
    cout << ((i <= 30) ? i : -1) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

// 09
#include <iostream>

using namespace std;

int main() {
  for (int n; cin >> n, n;) {
    bool f[50][31] = {{}};
    for (int i = 0; i < n; i++) {
      int nf;
      cin >> nf;
      while (nf--) {
        int d;
        cin >> d;
        f[i][d] = true;
      }
    }
    long long m[30];
    for (int i = 0; i < n; i++) {
      m[i] = 1LL << i;
    }
    int i;
    for (i = 1; i <= 30; i++) {
      long long cm = 0;
      for (int j = 0; j < n; j++) {
        if (f[j][i]) {
          cm |= m[j];
        }
      }
      if (cm == (1 << n) - 1)
        break;
      for (int j = 0; j < n; j++) {
        if (f[j][i]) {
          m[j] = cm;
        }
      }
    }
    cout << ((i <= 30) ? i : -1) << endl;
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;
typedef long long Long;

int N;
bool Free[31][51];

bool input() {
  cin >> N;
  if (N == 0)
    return false;
  memset(Free, 0, sizeof(Free));
  for (int i = 0; i < N; i++) {
    int Count;
    cin >> Count;
    for (int j = 0; j < Count; j++) {
      int F;
      cin >> F;
      Free[F][i] = true;
    }
  }
  return true;
}

void solve() {
  Long dp[31][N];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < N; i++)
    dp[0][i] |= (1LL << i);
  for (int i = 1; i <= 30; i++) {
    for (int j = 0; j < N; j++) {
      dp[i][j] = dp[i - 1][j];
    }
    Long bit = 0;
    for (int j = 0; j < N; j++) {
      if (Free[i][j])
        bit |= dp[i][j];
    }
    for (int j = 0; j < N; j++) {
      if (Free[i][j])
        dp[i][j] |= bit;
      // cout << hex << dp[i][j] << endl;
    }
    if (bit == (1LL << N) - 1) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
}

int main() {
  while (input()) {
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int n;
int main() {
  while (cin >> n, n != 0) {
    vector<vector<int>> c(30 + 1);
    for (int i = 0; i < n; i++) {
      int f;
      cin >> f;
      for (int j = 0; j < f; j++) {
        int d;
        cin >> d;
        c[i].push_back(d);
      }
    }

    // for (int i = 0; i <= 30; i++) {
    //     for (int j = 0; j < c[i].size(); j++) {
    //         cout << c[i][j] << ' ';
    //     }
    // }

    long long flag = 0;
    bool found = false;
    for (int i = 1; i <= 30; i++) {
      for (int j = 0; j < c[i].size(); j++) {
        flag |= (1 << c[i][j]);
        // cout << flag << ' ';
        if (flag == (1 << (n + 1)) - 2) {
          cout << i << endl;
          found = true;
          break;
        }
      }
      if (found)
        break;
    }
    if (!found)
      cout << -1 << endl;
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(int argc, char *argv[]) {
  long long int n;
  while (cin >> n, n) {
    long long int sche[n];
    vector<long long int> used(n, 0);
    memset(sche, 0, sizeof(sche));
    for (int i = 0; i < n; i++) {
      used[i] += (1LL << i);
      int x;
      cin >> x;
      for (int j = 0; j < x; j++) {
        int tmp;
        cin >> tmp;
        sche[i] |= 1 << (tmp - 1);
      }
    }

    int day;
    for (day = 0; day <= 30; day++) {
      for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
          if ((sche[i] & (1LL << day)) && (sche[j] & (1LL << day))) {
            used[i] = used[j] = (used[i] | used[j]);
          }
        }
      }
      if (find(used.begin(), used.end(), (1LL << n) - 1) != used.end()) {
        std::cout << day + 1 << std::endl;
        break;
      }
    }
    if (day > 30) {
      std::cout << -1 << std::endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int main(int argc, char *argv[]) {
  int n;
  long long int sche[n];
  memset(sche, 0, sizeof(sche));
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      for (int j = 0; j < x; j++) {
        int tmp;
        cin >> tmp;
        sche[i] |= 1 << (tmp - 1);
      }
    }
    long long int used = 0;
    int day = 0;
    for (int k = 0; k < 30 && used != (1LL << n) - 1; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          if (i == j)
            continue;
          if ((sche[i] & (1LL << day)) > 0 && (sche[j] & (1LL << day)) > 0) {
            used |= (1LL << i);
            used |= (1LL << j);
          }
        }
      }
      day++;
    }
    if (day <= 30)
      std::cout << day << std::endl;
    else
      std::cout << -1 << std::endl;
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 100000000;

int main() {
  // freopen("test.txt", "r", stdin);
  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;

    vector<vector<int>> v(31);
    rep(i, n) {
      int m;
      cin >> m;
      rep(j, m) {
        int k;
        cin >> k;
        v[k].push_back(i);
      }
    }

    vector<ll> s(n); // i番目が持っている地図
    rep(i, n) {
      s[i] = (ll)1 << i;
      //			cout << s[i] << endl;
    }
    bool ok = false;
    for (int i = 1; i <= 30; i++) {
      ll map = 0;
      for (int k = 0; k < v[i].size(); k++) {
        map |= s[v[i][k]];
      }
      for (int k = 0; k < v[i].size(); k++) {
        s[v[i][k]] |= map;
      }
      rep(j, n) {
        if (s[j] + 1 == (ll)1 << n)
          ok = true;
      }
      if (ok) {
        cout << i << endl;
        break;
      }
    }

    if (!ok)
      cout << -1 << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 100000000;

int main() {
  freopen("test.txt", "r", stdin);
  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;

    vector<vector<int>> v(31);
    rep(i, n) {
      int m;
      cin >> m;
      rep(j, m) {
        int k;
        cin >> k;
        v[k].push_back(i);
      }
    }

    vector<ll> s(n); // i番目が持っている地図
    rep(i, n) { s[i] = 1 << i; }
    bool ok = false;
    for (int i = 1; i <= 30; i++) {
      int map = 0;
      for (int k = 0; k < v[i].size(); k++) {
        map |= s[v[i][k]];
      }
      for (int k = 0; k < v[i].size(); k++) {
        s[v[i][k]] |= map;
      }
      rep(j, n) {
        if (s[j] + 1 == 1 << n)
          ok = true;
      }
      if (ok) {
        cout << i << endl;
        break;
      }
    }

    if (!ok)
      cout << -1 << endl;
  }

  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

bool hav[60][60];
int n, k, z;
vector<int> v[50];

int main() {

  while (cin >> n && n) {

    for (int i = 0; i < 50; i++)
      v[i].clear();

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        hav[i][j] = 0;
      }
      hav[i][i] = 1;
    }

    for (int i = 0; i < n; i++) {
      cin >> k;
      while (k--) {
        cin >> z;
        v[z - 1].push_back(i);
      }
    }

    int ans = -1;

    for (int d = 0; d < 30; d++) {

      for (int i = 0; i < v[d].size(); i++) {
        for (int j = i + 1; j < v[d].size(); j++) {

          for (int r = 0; r < n; r++) {

            bool t = max(hav[v[d][i]][r], hav[v[d][j]][r]);

            hav[v[d][i]][r] = t, hav[v[d][j]][r] = t;
          }
        }
      }
      for (int i = 0; i < n; i++) {

        bool ok = true;

        for (int j = 0; j < n; j++) {
          if (!hav[i][j])
            ok = false;
        }

        if (ok) {
          ans = d + 1;
          goto loop;
        }
      }
    }
  loop:
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool hav[60][60];
int n, k, z;
vector<int> v[50];
int main() {
  while (cin >> n && n) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        hav[i][j] = 0;
      }
      hav[i][i] = 1;
    }
    for (int i = 0; i < n; i++) {
      cin >> k;
      while (k--) {
        cin >> z;
        v[z - 1].push_back(i);
      }
    }

    int ans = -1;
    for (int d = 0; d < 30; d++) {
      for (int i = 0; i < v[d].size(); i++) {
        for (int j = i + 1; j < v[d].size(); j++) {
          for (int r = 0; r < n; r++) {
            bool t = hav[v[d][i]][r] || hav[v[d][j]][r];
            hav[v[d][i]][r] = t, hav[v[d][j]][r] = t;
          }
        }
        bool ok = true;
        for (int j = 0; j < n; j++) {
          if (!hav[i][j])
            ok = false;
        }
        if (ok) {
          ans = d + 1;
          break;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int solve(int n, vector<vector<int>> &sched) {
  vector<long long> f(31, 0);

  for (int j = 0; j < n; ++j) {
    for (int k = 0; k < sched[j].size(); ++k) {
      if (sched[j][k]) {
        f[sched[j][k]] |= (1LL << j);
      }
    }
  }

  for (int j = 1; j <= 30; ++j) {
    long long t = f[j];
    for (int k = j - 1; k > 0; --k) {
      if (t & f[k]) {
        t |= f[k];
      }
    }

    if (t == (1LL << n) - 1) {
      return j;
    }
  }

  return -1;
}

int main() {
  int n;
  vector<vector<int>> sched;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    sched.resize(n);
    for (int j = 0; j < n; ++j) {
      int l;
      cin >> l;
      sched[j].resize(l);
      for (int k = 0; k < l; ++k) {
        cin >> sched[j][k];
      }
    }
    cout << solve(n, sched) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

/*
 4
 1 1
 2 2 3
 2 1 2
 3 3 4 5

      1 2 3 4 5
 0 :  o
 1 :    o o
 2 :  o o
 3 :      o o o
      | | |

 */

const int MAX = 50;

int par[MAX];

void init(int n) { fill(par, par + n, -1); }

int find(int x) {
  if (par[x] < 0)
    return x;
  return par[x] = find(par[x]);
}

bool unite(int x, int y) {
  int xx = find(x);
  int yy = find(y);
  if (xx == yy)
    return false;
  if (par[xx] < par[yy]) {
    par[xx] += par[yy];
    par[yy] = xx;
  } else {
    par[yy] += par[xx];
    par[xx] = yy;
  }
  return true;
}

bool same(int x, int y) { return find(x) == find(y); }

int main() {
  int n;
  vector<int> sched[30];
  while (true) {
    scanf("%d", &n);
    if (n == 0)
      break;
    init(30);
    for (int i = 0; i < n; ++i) {
      int m, a;
      scanf("%d", &m);
      for (int _ = 0; _ < m; ++_) {
        scanf("%d", &a);
        sched[--a].push_back(i);
      }
    }
    int rem = -1;
    int day = 0;
    for (day = 0; day < 30; ++day) {
      for (int i = 0; i < sched[day].size() - 1; ++i) {
        unite(sched[day][i], sched[day][i + 1]);
        rem = sched[day][i];
      }
      if (rem >= 0 && par[find(rem)] == -n)
        break;
    }
    printf("%d\\n", day < 30 ? day + 1 : -1);
    for (int i = 0; i < 30; ++i) {
      sched[i].clear();
    }
  }
  return 0;
}