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

#include <stdio.h>
#include <string.h>
/*
#define disp 51

void printDtoB(long long int n){
        int i, a[disp];
        for(i = disp - 1;i >= 0;i--){
                a[i] = n % 2;
                n /= 2;
        }
        for(i = 0;i < disp;i++){
                printf("%d",a[i]);
        }
        printf("\\n");
        return;
}*/

int main(void) {
  long long int f[50][31], tmp, flag, n, i, m, x, s[50][31], j;
  while (1) {
    scanf("%lld", &n);
    if (!n)
      break;
    memset(f, 0, sizeof(f));
    memset(s, 0, sizeof(f));
    for (i = 0; i < n; i++) {
      scanf("%lld", &m);
      for (j = 0; j < m; j++) {
        scanf("%lld", &x);
        s[i][x] = 1;
      }
    }
    for (i = 0; i < n; i++)
      f[i][0] = (long long int)1 << i;
    flag = 0;
    for (i = 1; i <= 30 && !flag; (!flag ? i++ : 0)) {
      tmp = 0;
      for (j = 0; j < n; j++) {
        if (s[j][i])
          tmp |= f[j][i - 1];
      }
      for (j = 0; j < n; j++) {
        if (s[j][i])
          f[j][i] = tmp;
        else
          f[j][i] = f[j][i - 1];
      }
      for (j = 0; j < n; j++) {
        if (f[j][i] == ((long long int)1 << n) - 1)
          flag = 1;
      }
    }
    if (flag)
      printf("%lld\\n", i);
    else
      printf("-1\\n");
    //		for(i = 0;i < n;i++)
    //			printDtoB(f[i][1]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>

int main(void) {
  int n, i, j, f[30][50], h, a;
  long long int dp[31][50], sum;
  while (1) {
    scanf("%d", &n);
    memset(f, 0, sizeof(f));
    for (i = 0; i < n; i++) {
      scanf("%d", &h);
      for (j = 0; j < h; j++) {
        scanf("%d", &a);
        f[a - 1][i] = 1;
      }
    }
    memset(dp, 0, sizeof(dp));
    for (i = 0; i < n; i++)
      dp[0][i] = 1 << i;
    for (i = 0; i < 30; i++) {
      sum = 0;
      for (j = 0; j < n; j++) {
        if (f[i][j])
          sum += dp[i][j];
        else
          dp[i + 1][j] = dp[i][j];
      }
      for (j = 0; j < n; j++) {
        if (f[i][j])
          dp[i + 1][j] = sum;
      }
    }
    for (i = 0; i <= 30; i++) {
      for (j = 0; j < n; j++) {
        if (dp[i][j] == (1 << n) - 1)
          break;
      }
      if (j != n)
        break;
    }
    printf("%d\\n", i);
    /*		for(i = 0;i <= 30;i++){
                            printf("day%2d: ",i);
                            for(j = 0;j < n;j++)
                                    printf("%d ",dp[i][j]);
                            printf("\\n");
                    }*/
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 1; i <= n; ++i)
int main(void) {
  int n;
  while (cin >> n, n) {
    bool sc[51][31] = {}; //[man][date]
    bool piece[51][51] = {};
    int ans = -1;
    rep1(i, n) {
      int f, date;
      cin >> f;
      rep1(j, f) {
        cin >> date;
        sc[i][date] = true;
      }
    }
    rep1(i, n) piece[i][i] = true;

    rep1(date, 30) {
      rep1(i, n) rep1(j, n) {
        if (sc[i][date] && sc[j][date]) {
          rep1(k, n) piece[j][k] = piece[i][k] |= piece[j][k];
        }
      }
      rep1(i, n) {
        bool gather = true;
        rep1(j, n) gather &= piece[i][j];
        if (gather) {
          ans = date;
          break;
        }
      }
      if (ans > 0)
        break;
    }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 1; i <= n; ++i)
int main(void) {
  int n;
  while (cin >> n, n) {
    bool sc[31][51] = {}; //[man][date]
    int num[51] = {};
    bool piece[51][51] = {};
    int ans = -1, f, m;
    rep1(date, n) {
      cin >> f;
      rep1(i, f) {
        cin >> m;
        sc[date][m] = true;
      }
    }
    rep1(i, n) piece[i][i] = true;

    rep1(date, 30) {
      rep1(i, n) {
        rep1(j, n) {
          if (sc[i][date] && sc[j][date]) {
            rep1(k, n) piece[j][k] = piece[i][k] |= piece[j][k];
          }
        }
      }

      rep1(i, n) {
        rep1(j, n) {
          if (!piece[i][j])
            break;
          if (i == n && j == n)
            ans = date;
        }
        if (ans > 0)
          break;
      }
      if (ans > 0)
        break;
    }
    cout << ans << endl;
  }

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


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

using namespace std;

array<array<bool, 31>, 50> g_schedule;

array<array<set<int>, 31>, 50> g_map; //[50][30]

int g_n;

int solution() {
  for (int i = 1; i <= 30; ++i) {
    vector<int> ables;
    for (int j = 0; j < g_n; ++j) {
      if (g_schedule[j][i])
        ables.push_back(j);
      else
        g_map[j][i] = g_map[j][i - 1];
    }

    set<int> gathers;
    for (auto able = ables.begin(); able != ables.end(); ++able) {
      for (auto it = g_map[*able][i - 1].begin();
           it != g_map[*able][i - 1].end(); ++it) {
        gathers.insert(*it);
      }
    }
    for (auto it = ables.begin(); it != ables.end(); ++it) {
      g_map[*it][i] = gathers;
    }

    for (int j = 0; j < g_n; ++j) {
      if (g_map[j][i].size() == g_n)
        return i;
    }
  }

  return -1;
}

int main() {
  while (true) {
    cin >> g_n;
    if (g_n == 0)
      break;
    for (int i = 0; i < g_n; ++i) {
      g_map[i][0].clear();
      g_map[i][0].insert(i);
    }

    for_each(g_schedule.begin(), g_schedule.end(),
             [](array<bool, 31> &line) { line.fill(false); });
    for (int i = 0; i < g_n; ++i) {
      int f;
      cin >> f;
      for (int j = 0; j < f; ++j) {
        int day;
        cin >> day;
        g_schedule[i][day] = true;
      }
    }

    cout << solution() << endl;
  }
}

Error: 0

Fixed submission:


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

using namespace std;

array<array<bool, 31>, 50> g_schedule;

array<array<vector<int>, 31>, 50> g_map; //[50][30]

int g_n;

int solution() {
  for (int i = 1; i <= 30; ++i) {
    vector<int> ables;
    for (int j = 0; j < g_n; ++j) {
      if (g_schedule[j][i])
        ables.push_back(j);
    }

    vector<int> gathers;
    for (int person = 0; person < ables.size(); ++person) {
      for (auto it = g_map[ables[person]][i - 1].begin();
           it != g_map[ables[person]][i - 1].end(); ++it) {
        gathers.push_back(*it);
      }
    }
    unique(gathers.begin(), gathers.end());

    for (int j = 0; j < g_n; ++j) {
      if (!g_schedule[j][i]) {
        g_map[j][i] = g_map[j][i - 1];
      }
    }

    for (auto it = ables.begin(); it != ables.end(); ++it) {
      g_map[*it][i] = gathers;
    }

    for (int j = 0; j < g_n; ++j) {
      if (g_map[j][i].size() == g_n)
        return i;
    }
  }

  return -1;
}

int main() {
  while (true) {
    for_each(g_schedule.begin(), g_schedule.end(),
             [](array<bool, 31> &line) { line.fill(false); });

    cin >> g_n;
    if (g_n == 0)
      break;
    for (int i = 0; i < g_n; ++i) {
      g_map[i][0].push_back(i);
    }

    for (int i = 0; i < g_n; ++i) {
      int f;
      cin >> f;
      for (int j = 0; j < f; ++j) {
        int day;
        cin >> day;
        g_schedule[i][day] = true;
      }
    }

    cout << solution() << endl;
  }
}
Problem p01136 (C++) — buggy submission, verdict: Runtime Error

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

#define for_(i, a, b) for (int i = a; i < b; ++i)
#define allof(a) a.begin(), a.end()
#define minit(a, b) memset(a, b, sizeof(a))

typedef long long lint;
typedef pair<int, int> pii;
typedef vector<int> Array;
typedef vector<Array> Matrix;

int n;
bool emp[55][33];

lint dp[2][55];

void solve() {
  minit(dp, -1);

  for_(i, 0, n) dp[0][i] = (1LL << i);

  for_(i, 0, 30) {
    int nw = i % 2, nx = (i + 1) % 2;
    // for_(j,0,n) cout << dp[nw][j] << " ";
    // cout << endl;

    for_(j, 0, n) {
      dp[nx][j] = dp[nw][j];

      if (emp[j][i]) {
        for_(k, 0, n) {
          if (j == k)
            continue;
          if (emp[k][i]) {
            dp[nx][j] |= dp[nw][k];
          }
        }
      }

      if (dp[nx][j] == (1LL << n) - 1) {
        cout << i + 1 << endl;
        return;
      }
    }
  }

  cout << -1 << endl;
}

int main() {
  while (cin >> n, n) {
    minit(emp, 0);
    for_(i, 0, n) {
      int f;
      cin >> f;
      for_(j, 0, f) {
        int d;
        cin >> d;
        --d;
        emp[i][d] = true;
      }
    }
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define for_(i, a, b) for (int i = a; i < b; ++i)
#define allof(a) a.begin(), a.end()
#define minit(a, b) memset(a, b, sizeof(a))

typedef long long lint;
typedef pair<int, int> pii;
typedef vector<int> Array;
typedef vector<Array> Matrix;

int n;
bool emp[33][55];

lint dp[55][33];

void solve() {
  minit(dp, -1);

  for_(i, 0, n) dp[0][i] = (1LL << i);

  for_(i, 0, 30) {
    int ok = 0;

    for_(j, 0, n) {
      if (emp[j][i])
        ok |= dp[i][j];
    }

    for_(j, 0, n) {
      if (emp[j][i]) {
        dp[i + 1][j] = dp[i][j] | ok;
        if (dp[i + 1][j] == (1LL << n) - 1) {
          cout << i + 1 << endl;
          return;
        }
      } else {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }

  cout << -1 << endl;
}

int main() {
  while (cin >> n, n) {
    minit(emp, 0);
    for_(i, 0, n) {
      int f;
      cin >> f;
      for_(j, 0, f) {
        int d;
        cin >> d;
        --d;
        emp[i][d] = true;
      }
    }
    solve();
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long ll;
ll n, used[51], day[51];

int solve() {
  vector<int> l;
  for (int i = 1; i <= 30; i++) {
    l.clear();
    for (int j = 0; j < n; j++)
      if ((day[j] >> i) % 2)
        l.push_back(j);
    for (int j = 0; j < l.size(); j++) {
      for (int k = 0; k < l.size(); k++)
        used[l[j]] = (used[l[j]] | used[l[k]]);
      if (used[l[j]] == ((ll)1 << n) - 1)
        return i;
    }
  }
  return -1;
}

int main() {
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      day[i] = 0, used[i] = ((ll)1 << i);
      ll a, b;
      cin >> a;
      while (a--)
        cin >> b, day[i] = (day[i] | (ll)1 << b);
    }
    cout << solve() << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long ll;
ll n, used[51], day[51];

int solve() {
  vector<int> l;
  for (int i = 1; i <= 30; i++) {
    l.clear();
    for (int j = 0; j < n; j++)
      if ((day[j] >> i) % 2)
        l.push_back(j);
    for (int j = 0; j < l.size(); j++) {
      for (int k = 0; k < l.size(); k++)
        used[l[j]] = (used[l[j]] | used[l[k]]);
      assert(used[i] < ((ll)1 << n));
      if (used[l[j]] == ((ll)1 << n) - 1)
        return i;
    }
  }
  return -1;
}

int main() {
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      day[i] = 0, used[i] = ((ll)1 << i);
      ll a, b;
      cin >> a;
      while (a--)
        cin >> b, day[i] = (day[i] | (ll)1 << b);
    }
    cout << solve() << endl;
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Runtime Error

#include <bitset>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef bitset<50> state;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    vector<vector<int>> schedule(31);

    vector<state> states(n);
    state final_state;
    for (int i = 0; i < n; ++i) {
      states[i].set(i);
      final_state |= states[i];

      int m;
      cin >> m;
      while (m--) {
        int d;
        cin >> d;
        schedule[d].push_back(i);
      }
    }

    bool found = false;
    for (int d = 1; d <= 30; ++d) {
      vector<int> s = schedule[d];
      state new_state;
      for (vector<int>::iterator it = s.begin(); it != s.end(); ++it) {
        new_state |= states[*it];
      }
      if (new_state == final_state) {
        cout << d << endl;
        found = true;
        break;
      }
      for (vector<int>::iterator it = s.begin(); it != s.end(); ++it) {
        states[*it] = new_state;
      }
    }
    if (!found) {
      cout << -1 << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bitset>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef bitset<50> state;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    vector<vector<int>> schedule(30);

    vector<state> states(n);
    state final_state;
    for (int i = 0; i < n; ++i) {
      states[i] |= (1 << i);
      final_state |= states[i];

      int m;
      cin >> m;
      while (m--) {
        int d;
        cin >> d;
        schedule[d].push_back(i);
      }
    }

    bool found;
    for (int d = 1; d <= 30; ++d) {
      vector<int> s = schedule[d];
      state new_state;
      for (vector<int>::iterator it = s.begin(); it != s.end(); ++it) {
        new_state |= states[*it];
      }
      if (new_state == final_state) {
        cout << d << endl;
        found = true;
        break;
      }
      for (vector<int>::iterator it = s.begin(); it != s.end(); ++it) {
        states[*it] = new_state;
      }
    }
    if (!found) {
      cout << -1 << endl;
    }
  }
}
Problem p01136 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(n) for (int i = 0; i < n; i++)
#define repp(j, n) for (int j = 0; j < n; j++)
#define reppp(i, m, n) for (int i = m; i < n; i++)
// #define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge {
  int from, to;
  ll cost;
};

int main() {
  int n;
  while (scanf("%d", &n) && n != 0) {
    int days[31][n];
    fill(days[0], days[31], 0);
    rep(n) {
      int m;
      scanf("%d", &m);
      repp(j, m) {
        int day;
        scanf("%d", &day);
        days[day][i] = 1;
      }
    }

    int ans = -1;
    bitset<50> people[n];
    rep(n) {
      bitset<50> bs(0uL);
      bs.set(i);
      people[i] = bs;
    }
    reppp(i, 1, 31) {
      bitset<50> bs(0uL);
      repp(p, n) {
        if (days[i][p])
          bs |= people[p];
      }
      if (bs.count() == n) {
        ans = i;
        break;
      }
      repp(p, n) {
        if (days[i][p])
          people[p] = bs;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(n) for (int i = 0; i < n; i++)
#define repp(j, n) for (int j = 0; j < n; j++)
#define reppp(i, m, n) for (int i = m; i < n; i++)
// #define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge {
  int from, to;
  ll cost;
};

int main() {
  int n;
  while (scanf("%d", &n) && n != 0) {
    vector<int> days[31];
    rep(n) {
      int m;
      scanf("%d", &m);
      repp(j, m) {
        int day;
        scanf("%d", &day);
        days[day].push_back(i);
      }
    }

    int ans = -1;
    bitset<50> people[n];
    rep(n) {
      bitset<50> bs(0uL);
      bs.set(i);
      people[i] = bs;
    }
    reppp(i, 1, 31) {
      bitset<50> bs(0uL);
      for (int p : days[i]) {
        bs |= people[p];
      }
      if (bs.count() == n) {
        ans = i;
        break;
      }
      for (int p : days[i]) {
        people[p] = bs;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p01136 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <vector>

int main() {
  int n;
  while (scanf("%d", &n), n) {
    bool tmp[30][50], v[30][50];
    bool end = false;
    for (int i = 0; i < 30; i++) {
      for (int j = 0; j < 50; j++)
        tmp[i][j] = false;
    }
    for (int i = 0; i < n; i++) {
      int f;
      scanf("%d", &f);
      for (int j = 0; j < f; j++) {
        int t;
        scanf("%d", &t);
        t--;
        tmp[t][i] = true;
      }
    }
    for (int i = 0; i < 30; i++) {
      for (int j = 0; j < 30; j++)
        for (int k = 0; k < 50; k++)
          v[j][k] = tmp[j][k];
      for (int j = i - 1; j >= 0; j--) {
        for (int k = 0; k < n; k++) {
          if (v[i][k] == true && v[j][k] == true) {
            for (int l = 0; l < n; l++) {
              if (v[j][l] == true)
                v[i][l] = true;
            }
            break;
          }
        }
      }
      bool ok = true;
      for (int j = 0; j < n; j++) {
        if (v[i][j] == false) {
          ok = false;
          break;
        }
      }
      if (ok) {
        printf("%d\\n", i + 1);
        end = true;
        break;
      }
    }
    if (!end)
      printf("-1\\n");
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <vector>

int par[50], rank[50];
bool v[30][50];

void init(int n) {
  for (int i = 0; i < n; i++) {
    rank[i] = 0;
    par[i] = i;
  }
}

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

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;

  if (rank[x] < rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rank[x] == rank[y])
      rank[x]++;
  }
}

void Unite(int x, int y, int n) {
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (v[x][i] == false || v[x][j] == false)
        continue;
      unite(i, j);
      v[y][i] = true;
      v[y][j] = true;
    }
  }
}

int main() {
  int n;
  while (scanf("%d", &n), n) {
    bool tmp[30][50];
    bool end = false;
    for (int i = 0; i < 30; i++) {
      for (int j = 0; j < 50; j++)
        tmp[i][j] = false;
    }
    for (int i = 0; i < n; i++) {
      int f;
      scanf("%d", &f);
      for (int j = 0; j < f; j++) {
        int t;
        scanf("%d", &t);
        t--;
        tmp[t][i] = true;
      }
    }
    for (int i = 0; i < 30; i++) {
      for (int j = 0; j < 30; j++)
        for (int k = 0; k < 50; k++)
          v[j][k] = tmp[j][k];
      init(n);
      Unite(i, i, n);
      for (int u = i; u > 0; u--) {
        bool ok = false;
        for (int j = 0; j < n; j++) {
          if (v[i][j] == true && v[u - 1][j] == true) {
            ok = true;
            break;
          }
        }
        if (ok)
          Unite(u, i, n);
      }
      int check = find(0);
      bool ok = true;
      for (int j = 0; j < n; j++) {
        if (check != find(j)) {
          ok = false;
          break;
        }
      }
      if (ok) {
        printf("%d\\n", i + 1);
        end = true;
        break;
      }
    }
    if (!end)
      printf("-1\\n");
  }
}
Problem p01136 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  while (scanf("%d", &n) && n) {

    int b[64] = {0};

    for (int i = 0; i < n; i++) {
      int x;
      scanf("%d", &x);
      for (int j = 0; j < x; j++) {
        int t;
        scanf("%d", &t);
        b[i] |= 1 << (t - 1);
      }
    }

    for (int i = 0; i < 30; i++) {
      int st = 1 << i;

      for (int j = 0; j < 30; j++) {
        for (int k = 0; k < n; k++) {
          if (st & b[k]) {
            for (int l = 1; l <= (st & b[k]); l <<= 1) {
              st |= (b[k] & l);
            }
          }
        }
      }

      bool ok = true;
      for (int j = 0; j < n; j++) {
        if (!(st & b[j]))
          ok = false;
      }
      if (ok) {
        printf("%d\\n", i + 1);
        goto OK;
      }
    }

    printf("-1\\n");

  OK:;
  }

  return (0);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int m;
int head[64], to[512], nxt[512];
bool vis[64];

int conSize(int v) {
  int ret = 1;
  vis[v] = true;

  for (int e = head[v]; e != -1; e = nxt[e]) {
    if (!vis[to[e]]) {
      ret += conSize(to[e]);
    }
  }

  return (ret);
}

int main() {
  int n;

  while (scanf("%d", &n) && n) {

    int b[64] = {0};

    for (int i = 0; i < n; i++) {
      int x;
      scanf("%d", &x);
      for (int j = 0; j < x; j++) {
        int t;
        scanf("%d", &t);
        b[i] |= 1 << (t - 1);
      }
    }

    for (int i = 1; i <= 30; i++) {
      m = 0;
      memset(vis, 0, sizeof(vis));
      memset(head, -1, sizeof(head));
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          if (j == k)
            continue;
          if ((b[j] & ((1 << i) - 1)) & (b[k] & ((1 << i) - 1))) {
            nxt[m] = head[j];
            head[j] = m;
            to[m] = k;
            m++;
            nxt[m] = head[k];
            head[k] = m;
            to[m] = j;
            m++;
          }
        }
      }

      if (conSize(0) == n) {
        printf("%d\\n", i);
        goto OK;
      }
    }

    printf("-1\\n");

  OK:;
  }

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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a;
  while (cin >> a, a) {
    vector<int> b[30];
    for (int c = 0; c < a; c++) {
      int d;
      cin >> d;
      for (int e = 0; e < d; e++) {
        int f;
        cin >> f;
        f--;
        b[f].push_back(c);
      }
    }
    for (int c = 0; c < 30; c++) {
      bool e[50]{};
      if (b[c].size())
        e[b[c][0]] = true;
      for (int d = c; d >= 0; d--) {
        bool f = false;
        for (int g = 0; g < b[d].size(); g++) {
          if (e[b[d][g]])
            f = true;
        }
        if (f) {
          for (int g = 0; g < b[d].size(); g++) {
            e[b[d][g]] = true;
          }
        }
      }
      bool k = true;
      for (int i = 0; i < a; i++) {
        if (!e[i])
          k = false;
      }
      if (k) {
        cout << c + 1 << endl;
        goto l;
      }
    }
    puts("-1");
  l:;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a;
  while (cin >> a, a) {
    vector<int> b[30];
    for (int c = 0; c < a; c++) {
      int d;
      cin >> d;
      for (int e = 0; e < d; e++) {
        int f;
        cin >> f;
        f--;
        b[f].push_back(c);
      }
    }
    for (int c = 0; c < 30; c++) {
      bool e[30]{};
      if (b[c].size())
        e[b[c][0]] = true;
      for (int d = c; d >= 0; d--) {
        bool f = false;
        for (int g = 0; g < b[d].size(); g++) {
          if (e[b[d][g]])
            f = true;
        }
        if (f) {
          for (int g = 0; g < b[d].size(); g++) {
            e[b[d][g]] = true;
          }
        }
      }
      bool k = true;
      for (int i = 0; i < a; i++) {
        if (!e[i])
          k = false;
      }
      if (k) {
        cout << c + 1 << endl;
        goto l;
      }
    }
    puts("-1");
  l:;
  }
}