alexjercan/bugnet huggingface dataset:
Problem p02234 (C++) — buggy submission, verdict: Runtime Error

/**
 * 	matrix chain multiplication
 * 	f(n,m) = multiply Mn*M(n+1)*...*M(m-1)*M(m)
 * 	f(n,n) = 1
 * 	r(n)=c(n-1)
 * 	f(n,n+1) = C(n) * R(n) * C(n+1) = c(n) * c(n-1) * c(n+1)
 * 	f(n,k,m) = f(n,k)*f(k+1,m)*C(n)*r(n)*c(k)
 * 	f(n,m) = min(f(n,k,m)
 */

#include <climits>
#include <cmath>
#include <iostream>

using namespace std;

int r[100] = {0};
int a[100][100] = {0};

int f(int n, int m);
int f(int n, int k, int m);

int f(int n, int k, int m) {
  return f(n, k) + f(k + 1, m) + (r[n] * r[k + 1] * r[m + 1]);
}

int f(int n, int m) {
  if (n == m)
    return 0;
  int &ra = a[n][m];
  if (ra)
    return ra;
  ra = INT_MAX;
  for (int k = n; k < m; k++) {
    int ans = f(n, k, m);
    if (ans < ra)
      ra = ans;
  }
  return ra;
}

int main() {
  int rr = 0;
  int cc = 0;
  int n = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> rr >> cc;
    r[i] = rr;
    r[i + 1] = cc;
  }
  for (int i = 0; i < n - 1; i++) {
    a[i][i + 1] = r[i] * r[i + 1] * r[i + 2];
  }
  int ans = f(0, n - 1);
  cout << ans << endl;
}

Error: 0

Fixed submission:

/**
 * 	matrix chain multiplication
 * 	f(n,m) = multiply Mn*M(n+1)*...*M(m-1)*M(m)
 * 	f(n,n) = 1
 * 	r(n)=c(n-1)
 * 	f(n,n+1) = C(n) * R(n) * C(n+1) = c(n) * c(n-1) * c(n+1)
 * 	f(n,k,m) = f(n,k)*f(k+1,m)*C(n)*r(n)*c(k)
 * 	f(n,m) = min(f(n,k,m)
 */

#include <climits>
#include <cmath>
#include <iostream>

using namespace std;

int r[45] = {0};
int a[100][100] = {0};

int f(int n, int m);
int f(int n, int k, int m);

int f(int n, int k, int m) {
  return f(n, k) + f(k + 1, m) + (r[n] * r[k + 1] * r[m + 1]);
}

int f(int n, int m) {
  if (n == m)
    return 0;
  int &ra = a[n][m];
  if (ra)
    return ra;
  ra = INT_MAX;
  for (int k = n; k < m; k++) {
    int ans = f(n, k, m);
    if (ans < ra)
      ra = ans;
  }
  return ra;
}

int main() {
  int rr = 0;
  int cc = 0;
  int n = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> rr >> cc;
    r[i] = rr;
    r[i + 1] = cc;
  }
  for (int i = 0; i < n - 1; i++) {
    a[i][i + 1] = r[i] * r[i + 1] * r[i + 2];
  }
  int ans = f(0, n - 1);
  cout << ans << endl;
}
Problem p02234 (C++) — buggy submission, verdict: Runtime Error

#include <climits>
#include <iostream>
using namespace std;
int m[100][100];

int MCM(int p[], int n) {
  for (int i = 0; i <= n; i++)
    m[i][i] = 0;
  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n - l + 1; i++) {
      int j = i + l - 1;
      m[i][j] = INT_MAX;
      for (int k = i; k <= j - 1; k++) {
        int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
        if (m[i][j] > q) {
          m[i][j] = q;
        }
      }
    }
  }
  return m[1][n];
}

int main() {
  int n, p[200];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i] >> p[i + 1];
  }
  cout << MCM(p, n) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <climits>
#include <iostream>
using namespace std;
int m[100][100];

int MCM(int p[], int n) {
  for (int i = 0; i <= n; i++)
    m[i][i] = 0;
  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n - l + 1; i++) {
      int j = i + l - 1;
      m[i][j] = INT_MAX;
      for (int k = i; k <= j; k++) {
        int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
        if (m[i][j] > q) {
          m[i][j] = q;
        }
      }
    }
  }
  return m[1][n];
}

int main() {
  int n, p[200];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i] >> p[i + 1];
  }
  cout << MCM(p, n) << endl;
  return 0;
}
Problem p02234 (C++) — buggy submission, verdict: Runtime Error

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

int MCM(int p[], int n) {
  vector<vector<int>> m(n + 1, vector<int>(n + 1));
  for (int i = 0; i <= n; i++)
    m[i][i] = 0;
  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n - l + 1; i++) {
      int j = i + l - 1;
      m[i][j] = INT_MAX;
      for (int k = i; k <= j - 1; k++) {
        int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
        if (m[i][j] > q) {
          m[i][j] = q;
        }
      }
    }
  }
  return m[1][n];
}

int main() {
  int n, p[200];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i] >> p[i + 1];
  }
  cout << MCM(p, n) << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int MCM(int p[], int n) {
  vector<vector<int>> m(n, vector<int>(n));
  for (int i = 0; i <= n; i++)
    m[i][i] = 0;
  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n - l + 1; i++) {
      int j = i + l - 1;
      m[i][j] = INT_MAX;
      for (int k = i; k <= j - 1; k++) {
        int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
        if (m[i][j] > q) {
          m[i][j] = q;
        }
      }
    }
  }
  return m[1][n];
}

int main() {
  int n, p[200];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i] >> p[i + 1];
  }
  cout << MCM(p, n) << endl;
  return 0;
}
Problem p02237 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int adj[100][100] = {};
  int n;
  cin >> n;
  int a, b, c;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    // adj[num1-1]?????\\??????

    for (int j = 0; j < b; j++) {
      cin >> c;
      adj[a - 1][c - 1] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j)
        cout << " ";
      cout << adj[i][j];
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int adj[100][100] = {};
  int n;
  cin >> n;
  int num1, num2, num3;
  for (int i = 0; i < n; i++) {
    cin >> num1 >> num2;
    // adj[num1-1]?????\\??????
    for (int j = 0; j < num2; num2++) {
      cin >> num3;
      adj[num1 - 1][num3 - 1] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j)
        cout << " ";
      cout << adj[i][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p02237 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int N;

int main() {
  cin >> N;

  vector<vector<bool>> M(N, vector<bool>(N));

  int u, k, v;

  for (int i = 0; i < N; i++) {
    cin >> u >> k;

    for (int i = 0; i < k; i++) {
      cin >> v;

      M[u - 1][v - 1] = true;
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cout << M[i][j];

      if (j != N - 1) {
        cout << ' ';
      }
    }

    cout << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int N;

int main() {
  cin >> N;

  vector<vector<bool>> M(N, vector<bool>(N));

  int u, k, v;

  for (int i = 0; i < N; i++) {
    cin >> u >> k;

    for (int i = 0; i < k; i++) {
      cin >> v;

      M[u - 1][v - 1] = true;
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N;) {
      cout << M[i][j];

      cout << ' ';
    }

    cout << endl;
  }

  return 0;
}
Problem p02237 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
static const int N = 100;

int main() {
  int MA[N][N];
  int n, u, k, v;

  cin >> n;

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

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--;
      MA[u][v] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j)
        cout << " ";
      cout << MA[i][j];
    }
    cout << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
static const int N = 100;

int main() {
  int m[N][N];
  int n, u, k, v;

  cin >> n;

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

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; i < k; j++) {
      cin >> v;
      v--;
      m[u][v] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j)
        cout << " ";
    }
    cout << endl;
  }

  return 0;
}
Problem p02237 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
static const int N = 100;

int main() {
  int M[N][N]; // 0 オリジンの配列
  int n, u, k, v;

  cin >> n;

  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      M[i][j] = 0;

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--; // 0 オリジンへ変換
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--;         // 0 オリジンへ変換
      M[u][v] = 1; // u と v の間に辺を張る
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j)
        cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
static const int N = 100;

int main() {
  int M[N][N]; // 0 オリジンの配列
  int n, u, k, v;

  cin >> n;

  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      M[i][j] = 0;

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--; // 0 オリジンへ変換
    for (int j = 0; i < n; j++) {
      cin >> v;
      v--;     // 0 オリジンへ変換
      M[u][v]; // u と v の間に辺を張る
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j)
        cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

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

#include <iostream>
using namespace std;
static const int N = 100;

int main() {
  int M[N][N];
  int n, u, k, v;

  cin >> n;

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

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j)
        cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
static const int N = 100;

int main() {
  int M[N][N];
  int n, u, k, v;

  cin >> n;

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

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; i < n; j++) {
      if (j)
        cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
using namespace std;
int n, u, k, p;
bool adm[105][105];
int main() {
  memset(adm, false, sizeof(adm));
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &u, &k);
    while (k--) {
      scanf("%d", &p);
      adm[u][p] = true;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      printf("%d%c", adm[i][j] ? 1 : 0, j == n ? '\\n' : ' ');
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

static const int N = 100;

int main() {
  int M[N][N];
  int n, u, v, k;
  cin >> n;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      M[i][j] = 0;
    }
  }

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--; //
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--; //
      M[u][v] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j)
        cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p02237 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int n;
int k;

int main() {
  int num;
  cin >> n;
  int adj[n][n];
  int rin;
  int i = 0, j = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      adj[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    cin >> num >> k;
    num--;
    for (j = 0; j < k; j++) {
      cin >> rin;
      rin--;
      adj[num][rin] = 1;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (j)
        cout << " ";
      cout << adj[i][j];
    }
    cout << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int n;
int k;

int main() {
  int adj[n + 10][n + 10];
  int num;
  cin >> n;
  int rin;
  int i = 0, j = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      adj[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    cin >> num >> k;
    num--;
    for (j = 0; j < k; j++) {
      cin >> rin;
      rin--;
      adj[num][rin] = 1;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (j)
        cout << " ";
      cout << adj[i][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p02237 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, m, l, i, j, p;
  cin >> n;
  int f[1000][1000];
  for (i = 0; i < n; i++) {
    cin >> m;
    cin >> p;
    for (j = 0; j < p; j++) {
      cin >> l;
      f[m - 1][l - 1] = 1;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n - 1; j++) {
      cout << f[i][j] << " ";
    }
    cout << f[i][n - 1] << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  cin >> n;
  int f[10][10] = {};
  for (int i = 0; i < n; i++) {
    cin >> m;
    for (int j = 0; i < m; j++) {
      cin >> l;
      f[m][l] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 1; j++) {
      cout << f[i][j] << " ";
    }
    cout << f[i][n] << endl;
  }
}
Problem p02237 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
static const int N = 100;

int main() {
  int M[N][N];
  int n, u, k, v;

  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      M[i][j] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j)
        cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
static const int N = 100;

int main() {
  int M[N][N];
  int n, u, k, v;

  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++)
      M[i][j] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; k < n; j++) {
      if (j)
        cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p02237 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define DUMP(list)                                                             \\
  cout << "{ ";                                                                \\
  for (auto nth : list) {                                                      \\
    cout << nth << " ";                                                        \\
  }                                                                            \\
  cout << "}" << endl
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)             \\
    ;

using namespace std;

int main() {

  int n;
  cin >> n;
  vector<vector<int>> ans(n, vector<int>(n, 0));

  rep(i, n) {
    int u, k;
    cin >> u >> k;
    u--;
    rep(j, k) {
      int v;
      cin >> v;
      v--;
      ans[u][v] = 1;
    }
  }

  rep(i, n) {
    rep(j, n - 1) { cout << ans[i][j] << " "; }
    cout << ans[i][n - 1] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define DUMP(list)                                                             \\
  cout << "{ ";                                                                \\
  for (auto nth : list) {                                                      \\
    cout << nth << " ";                                                        \\
  }                                                                            \\
  cout << "}" << endl
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)             \\
    ;

using namespace std;

int main() {

  int n;
  cin >> n;
  vector<vector<int>> ans(n, vector<int>(4, 0));

  rep(i, n) {
    int u, k;
    cin >> u >> k;
    u--;
    rep(j, k) {
      int v;
      cin >> v;
      v--;
      ans[u][v] = 1;
    }
  }

  rep(i, n) {
    rep(j, n - 1) { cout << ans[i][j] << " "; }
    cout << ans[i][n - 1] << endl;
  }

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

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
const int INF = 1e9;

using namespace std;
vector<int> adj[100];
int res[105][105] = {0};

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    int u, k;
    cin >> u >> k;
    REP(j, k) {
      int tmp;
      cin >> tmp;
      res[u][tmp] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < n; j++)
      cout << res[i][j] << " ";
    cout << res[i][n] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
const int INF = 1e9;

using namespace std;
vector<int> adj[100];
int res[100][100] = {0};

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    int u, k;
    cin >> u >> k;
    REP(j, k) {
      int tmp;
      cin >> tmp;
      res[u][tmp] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < n; j++)
      cout << res[i][j] << " ";
    cout << res[i][n] << endl;
  }
  return 0;
}
Problem p02237 (C++) — buggy submission, verdict: Runtime Error

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

const double pi = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
#define INF (1 << 29)
#define INFLL (1L << 29)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst;
  Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Cost> Array;
typedef vector<Array> Matrix;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

#define MAX_N 101

int G[MAX_N][MAX_N];

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    rep(j, k) {
      int node_num;
      cin >> node_num;
      G[u][node_num] = 1;
    }
  }
  REP(i, 1, n + 1) {
    REP(j, 1, n + 1) {
      if (j != 1)
        cout << " ";
      cout << G[i][j];
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

const double pi = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
#define INF (1 << 29)
#define INFLL (1L << 29)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst;
  Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Cost> Array;
typedef vector<Array> Matrix;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

#define MAX_N 100

int G[MAX_N][MAX_N];

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    rep(j, k) {
      int node_num;
      cin >> node_num;
      G[u][node_num] = 1;
    }
  }
  REP(i, 1, n + 1) {
    REP(j, 1, n + 1) {
      if (j != 1)
        cout << " ";
      cout << G[i][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p02237 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> A(n, vector<int>(n, 0));
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    // 1~n???index?????¨????????????????????????????????????1????????????0~n-1????????????
    k -= 1;
    int u;
    cin >> u;
    for (int j = 0; j < u; ++j) {
      int v;
      cin >> v;
      v -= 1;
      A[k][v] = 1;
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cout << A[i][j];
      if (j != n - 1)
        cout << " ";
    }
    cout << endl;
  }
}

Error: WA

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> A(n, vector<int>(n, 0));
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    int u;
    cin >> u;
    for (int j = 0; j < u; ++j) {
      int v;
      cin >> v;
      A[k - 1][v] = 1;
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cout << A[i][j] << " ";
    }
    cout << endl;
  }
}
Problem p02237 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int g[1001][1001]; // 要素を0で初期化
  int n, a, b, c;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      g[i][j] = 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    for (int i = 0; i < b; ++i) {
      cin >> c;
      g[a - 1][c - 1] = 1; /* code */
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (j == n - 1) {
        cout << g[i][j] << endl;
      } else {
        cout << g[i][j] << " ";
      }
    }
  }
}

Error: -11

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int g[10010][10010] = {}; // 要素を0で初期化
  int n, a, b, c;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    for (int i = 0; i < b; ++i) {
      cin >> c;
      g[a - 1][c - 1] = 1; /* code */
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (j == n - 1) {
        cout << g[i][j] << endl;
      } else {
        cout << g[i][j] << " ";
      }
    }
  }
}