Go: package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	graph := make([][]int, N)
	for i := range graph {
		graph[i] = make([]int, N)
		var u, k int
		fmt.Scan(&u, &k)
		for j := 0; j < k; j++ {
			var v int
			fmt.Scan(&v)
			v--
			graph[i][v] = 1
		}
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(graph[i][j])
		}
		fmt.Println()
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector< vector< int > > adjMatrix (n, vector< int > (n, 0));
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int holder;
      cin >> holder;
      adjMatrix[u-1][holder-1] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << adjMatrix[i][j];
      if (j == n-1)
	cout << endl;
      else
	cout << ' ';
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
    
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <limits>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<vector<int>> vec(n);
    vector<int> SIZE;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        int num;
        cin >> num;
        SIZE.push_back(num);
        for(int j = 0;j< num;j++){
            int y;
            cin >> y;
            vec[x-1].push_back(y-1) ;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            bool hantei=0;
            for(int k=0;k<SIZE[i];k++){
                if(vec[i][k]==j) {cout << 1 <<" "; hantei=1;}
            }
            if(hantei==0) cout <<0<<" ";
        }cout << endl;
    }
}

C++: #include <iostream>

class Vertex {
public:
    int u, k, *v;
};

using namespace std;

int main() {
    int **matrix = nullptr, num = 0;
    Vertex *vertex;

    cin >> num;
    matrix = (int **)malloc(num * sizeof(int *));
    for(int i=0; i<num; ++i)
        matrix[i] = (int *)malloc(num * sizeof(int));
    
    for(int i=0; i<num; ++i) {
        for(int j=0; j<num; ++j) {
            matrix[i][j] = 0;
        }
    }
    
    vertex = new Vertex[num];
    for(int i=0; i<num; ++i) {
        cin >> vertex[i].u >> vertex[i].k;
        vertex[i].v = new int[vertex[i].k];
        for(int j=0; j<vertex[i].k; ++j) {
            cin >> vertex[i].v[j];
            matrix[vertex[i].u-1][vertex[i].v[j]-1] = 1;
        }
    }

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

    return 0;
}

C++: #include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


//////////////////////////////////////
#include <iostream>
using namespace std;
#define dp(arg) do { cout << #arg << ":"; dprint(arg); } while(0)

template <typename T> void dprint(T arg) { cout << arg << "\n"; }
template <typename T> void dprint(const vector<T>& arg) { for_each(begin(arg), end(arg), [](T value){ cout << value << " "; }   ); cout << "\n";  }
template <typename T> void dprint(const vector<vector<T>>& arg) { for_each(begin(arg), end(arg), [=](vector<T> arg2){ dprint(arg2); cout << "\n";} );  }

// #define dprint(arg) ;
//////////////////////////////////////

using namespace std;
int main() {

    int n;
    cin >> n;

    int adj[n][n];
    memset(adj, 0, sizeof(int) * n * n);

    int v, k;
    int a;
    REP(i, n) {
        cin >> v >> k;
        REP(j, k){
            cin >> a;
            adj[v-1][a-1] = 1;
        }
    }

    REP(i, n) {
        REP(j, n - 1) {
            cout << adj[i][j] << " ";
        }
        cout << adj[i][n-1] << "\n";
    }

}

C++: #include <iostream>
#include <vector>
#include <cstring>
using namespace std;

class branch{
  int to;
  branch(int to){
    this->to = to;
  }
};

int main(){
  int n; cin >> n;
  vector<branch> graph[n+1];
  int g[n+1][n+1];
  memset(g, 0, sizeof(g));

  int v, k, to;
  for(int i=0; i<n; i++){
    cin >> v;
    cin >> k;
    for(int j=0; j<k; j++){
      cin >> to;
      g[v][to]=1;
    }
  }

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

  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int G[101][101];

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

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#include<sstream>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

bool graph[101][101];

int main() {
	int N;	
	int id,node_size,neighber;
	cin >> N;

	rep(y,N) {
		rep(x,N) {
			graph[y][x] = 0;
		}
	}

	rep(i,N) {
		cin >> id >> node_size;
		rep(j,node_size) {
			cin >> neighber;
			graph[id][neighber] = 1;	
		}
	}

	REP(y,1,N+1) {
		REP(x,1,N+1) {
			cout << graph[y][x];
			if (x != N) {
				cout << " ";
			}
		}
		cout << endl;
	}

	return EXIT_SUCCESS;
}

C++: #include <algorithm>
#include <iostream>
using namespace std;
int main () {
  int n;
  cin >> n;
  int A[n][n];
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++)
      A[i][j] = 0;
  }
  while (n>0) {
    int u;
    cin >> u;
    int k;
    while (cin>>k && k>0) {
      int v;
      cin >> v;
      A[u-1][v-1] = 1;
      k--;
    }
    n--;
  }
  for (int i=0; i<n; i++) {
    for (int j=0; j<n-1; j++)
      cout << A[i][j] << " ";
    cout << A[i][n-1] << endl;
  }
}

C++: #include<iostream>
#include <string.h>
using namespace std;
int main(){
    int N;
    int u[101],k[101],a[101],d[101][101];
    memset(d,0,sizeof(d));
    cin>>N;
    for(int i=1;i<=N;++i){
        cin>>u[i]>>k[i];
        for(int j=0;j<k[i];++j){
            cin>>a[j];
            d[u[i]][a[j]]=1;
        }
        for(int m=1;m<=N;++m){
            cout<<d[i][m]<<' ';
        }
        cout<<endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

struct Node {
  int num = 0,
      deg = 0;
  vi v;
  Node(int num = 0): num(num) {}
};

int main() {
  int n;
  cin >> n;
  
  vector<Node> g(n);
  rep(i, n) {
    int num;
    cin >> num;
    auto nd = new Node(num);
    cin >> nd->deg;
    rep(j, nd->deg) {
      int v;
      cin >> v;
      nd->v.push_back(v);
    } 

    g[i] = *nd;
  }
  
  rep(i, n) {
    auto nd = g[i];
    int r = 0;
    rep(j, n) {
      int p;
      if (nd.v.size() && r < nd.v.size() && j + 1 == nd.v[r]) {
        p = 1;
        r++;
      } else p = 0;
      printf(j == n - 1 ? "%d\n" : "%d ", p);
    }
  }
}