Go: package main

/*
グラフの表現 隣接行列による表現
*/

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		ints := eGetInts(scanner)
		num := ints[0]
		for j := 0; j < ints[1]; j++ {
			g[num-1][ints[j+2]-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		s := fmt.Sprint(g[i])
		fmt.Println(s[1 : len(s)-1])
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define NOTUSED 0
using Graph=vector<vector<int>>;

int main(){
    int n;
    cin>>n;

    // 隣接リストGを受け取る
    Graph G(n+1);
    G[0]={NOTUSED};
    REP(i,n){
        int u,k;
        cin>>u>>k;
        G[u].resize(k);
        REP(j,k){
            cin>>G[u][j];
        }
    }

    // 隣接行列Aを作成
    Graph A(n+1);
    A[0]={NOTUSED};
    for(int i=1; i<=n; i++){
        A[i].assign(n+1,0);
        A[i][0]=NOTUSED;
        REP(j,G[i].size()){
            A[i][G[i][j]]=1;
        }
    }

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

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <cstdlib>
#include <queue>
#include <vector>
#include <set>

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

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

#define int long long

const int N = 100 + 1;

int32_t main(){
  	int n;
  	cin >> n;
  	int g[n][n] = {};
  	for(int i = 0; i < n; i++){	
       int m, deg;
       cin >> m >> deg;
       for(int i = 0; i < deg; i++){
		  int x;
		  cin >> x;
		  g[m - 1][x - 1] = 1;
		}
    }
   for(int i = 0; i < n; i++){
	 for(int j = 0; j < n; j++){
		 if (j) cout << " ";
		 cout << g[i][j];
	   }
	  cout << endl;  
	 } 
}

C++: #include<bits/stdc++.h>

using namespace std;

int main()
{
    int n, d, u, v, i, j, x;

    cin >> n;

    bool adjmat[n + 1][n + 1];

    for(i = 0; i <= n; i++)
    {
        for(j = 0; j <= n; j++)
            adjmat[i][j] = false;
    }

    for(i = 0; i < n; i++)
    {
        cin >> x >> d;
        for(j = 0; j < d; j++)
        {
            cin >> u;
            adjmat[x][u] = true;
        }
    }

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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

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 long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(int argc, char const *argv[]) {
  int n,v,d; std::cin >> n;
  REP0(i,n){
    std::cin >> v >> d;
    VI row(n,0);
    REP0(j,d){
      std::cin >> v;
      row[v-1]=1;
    }
    REP0(j,n){
      std::cout << row[j];
      if (j<n-1) std::cout << " ";
    }
    std::cout << '\n';
  }

  return 0;
}

C++: #include <iostream>
#include <queue>

using namespace std;

#define MAX 110
int matrix[MAX][MAX];
int dst[MAX];

void input(int num){
    for(int i=0;i<MAX;i++){
        dst[i] = -1;
        for(int j=0;j<MAX;j++){
            matrix[i][j] = 0;
        }
    }
    for(int i=1;i<=num;i++){
        int v; cin >> v;
        int tmp; cin >>tmp;
        for(int j=0;j<tmp;j++){
            int vi; cin >> vi;
            matrix[v-1][vi-1] = 1;
        }
    }
}

void bfs(){

}

int main(){
    int num; cin >> num;
    input(num);

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

}