Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		arr[u-1] = make([]int, n)
		for j := 0; j < k; j++ {
			n := scanInt()
			arr[u-1][n-1] = 1
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for _, col := range arr {
		fmt.Fprintln(w, strings.Trim(fmt.Sprint(col), "[]"))
	}
	w.Flush()
}

Python: """
隣接リストで与えられる有向グラフを，隣接行列で構成しなおす
"""
n = int(input())

for i in range(n):
    mat = [0 for _ in range(n)]
    l = list(map(int, input().split()))
    deg = l[1]
    for r in range(deg):
        index = l[r+2]-1
        mat[index] = 1
    print(' '.join(map(str, mat)))

Python: n = int(input())
A = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(n):
    tmp_u = list(map(int, input().split()))
    vs = tmp_u[2:]
    for v in vs: 
        A[tmp_u[0]-1][v-1] = 1
       
for i in range(n):
    tmp_A = A[i]
    tmp_A = map(str, tmp_A)
    tmp_A = ' '.join(tmp_A)
    print(tmp_A)

Python: n=int(input())
dp = [[0 for i in range(n)] for j in range(n)] 

for _ in range(n):
    inputs = list(map(int, input().split()))
    u = inputs[0]
    k = inputs[1]
    v = inputs[2:]
    for each in v:
        dp[u-1][each-1] = 1
for i in range(n):
    for j in range(n):
            print(dp[i][j],end=' ')
    print()

Python: N = int(input())
L = [list(map(int, input().split())) for i in range(N)]
adj = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
  for node in L[i][2:]:
    adj[i][node-1] = 1

for a in adj:
  print(" ".join(map(str, a)))

Python: n=int(input());
G=[[0 for i in range(n)]for j in range(n)]
for i in range(n):
    list=[int(m) for m in input().split()]
    u=list[0]
    k=list[1]
    for j in range(2,len(list)):
        v=list[j]
        G[u-1][v-1]=1
for i in range(n):
    for j in range(n):
        if j!=n-1:
            print(G[i][j],end=" ")
        else:
            print(G[i][j],end="\n")

Python: 
N = int(input())

# initialize
ans = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    a = list(map(int, input().split()))
    id = a[0]
    jisu = a[1]
    for j in range(jisu):
        c = a[j+2]
        ans[i][c-1] = 1

for i in range(N):
    for j in range(N):
        if j != N-1:
            print(ans[i][j], end=" ")
        else:
            print(ans[i][j])

Python: N=int(input())
for _ in[0]*N:
 r=[0]*N
 for i in input().split()[2:]:r[int(i)-1]=1
 print(*r)

Python: def Main():
    N = int(input())
    adj = [[0]*N for i in range(N)]

    for n in range(N):
        u, k, *V = map(int, input().split())
        
        if k > 0:
           for i in V:
            adj[u - 1][i - 1] = 1

    for i in range(N):
        print(*adj[i])

Main()

Python: import sys


class Graph:
    def __init__(self, nodes={}):
        self.nodes = nodes


n = int(input())
G = Graph()
for line in sys.stdin:
    numList = line.split()
    G.nodes[int(numList[1])] = list(map(int, numList[1:]))

for _ in range(n):
    out = ''
    for i in range(n):
        if i + 1 != n:
            out += '0 ' if i + 1 in G.nodes[1] else '1 '
        else:
            out += '0' if i + 1 in G.nodes[1] else '1'
    print(out)

Python: n = int(input())
in_list = []
for i in range(n):
    in_list.append(list(map(int, input().split())))

matrices = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
    inp = in_list[i]
    u = inp[0]
    k = inp[1]
    for j in range(k):
        m = inp[j+2]
        matrices[i][m-1] = 1

for i in range(n):
    s = ""
    for m in matrices[i]:
        s += str(m) + " "
    print(s)

Python: n = int(input())
A = [[0 for i in range(n)] for i in range(n)]
for _ in range(n):
    u, k, *v = [int(i) for i in input().split()]
    for vi in v:
        A[u-1][vi-1] = 1

for i in range(n):
    print(*A[i])

Python: import sys
input = sys.stdin.readline
n = int(input())
G = {i: [] for i in range(1, n+1)}
for _ in range(n):
    tmp = list(map(int, input().split()))
    G[tmp[0]] += tmp[2:] if tmp[1]>0 else []

adj = [[0]*(1+n) for _ in range(1+n)]
for i in range(1, n+1):
    for j in G[i]:
        adj[i][j] = 1
for i in range(1, n+1):
    print(*adj[i][1:])

Python: # coding: UTF-8
n = int(input())
Ans =[ [0 for i in range(n)] for j in range(n)]
for l in range(n):
  raw = list(map(int,input().split()))
  i = raw[0]
  d = raw[1]
  for m in range(2,d+2):
    Ans[i-1][raw[m]-1] = 1

for i in range(n):
  print(" ".join(map(str,Ans[i])))

Python: N=int(input())
#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [[0 for j in range(N)] for i in range(N)]

for i in range(N):
    T=list(map(int,input().split()))
    if T[1]!=0:
        
        for j in range(T[1]):
            S[i][T[j+2]-1]=1

for i in S:
    print(*i)

Python: # -*- coding: utf-8 -*-


if __name__ == '__main__':

    n = int(input())
    M = [[0 for i in range(n)] for j in range(n)]
    for _ in range(n):
        l = list(map(int, input().split(" ")))
        u = l[0]
        k = l[1]
        if k != 0:
            for v in l[2:]:
                M[u-1][v-1] = 1
        
    for r in M:
        print(" ".join(map(str, r)))

Python: def main():
    n = int(input())
    
    graph = [[0 for _ in range(n)] for _ in range(n)]

    for _ in range(n):
        u, k, *v_s = map(int, input().split(' '))
        for j in range(k):
            graph[u-1][v_s[j-1]-1] = 1
    
    for row in graph:
        print(' '.join(map(str, row)))


if __name__ == "__main__":
    main()

Python: n = int(input())

A = [[0 for i in range(n)] for j in range(n)]

for i in range(n):

	B = input().split()

	if B[1]!=0:
		for j in range(int(B[1])):
			#B[2+j]
			A[i][int(B[2+j])-1] = 1

for i in range(n):
	for j in range(n):
		print(A[i][j], end=" ")
	print(end="\n")

Python: from sys import stdin
n = int(stdin.readline())
v = [[0] * n for _ in range(n)]
for u in range(n):
    l = [int(j) for j in stdin.readline().split()]
    for k in l[2:]:
        v[u][k - 1] = 1
    print(*v[u])

Python: n=int(input())
V=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
	v=[int(j) for j in input().split(" ")]
	u=v.pop(0)
	k=v.pop(0)
	for j in range(k):
		V[u-1][v[j]-1]=1



for i in range(n):
	print(" ".join([str(j) for j in V[i]]))

Python: n = int(input())

for i in range(n):
    nums = list(map(int, input().split()))
    ans = ['0'] * n
    for j in nums[2:]:
        ans[j-1] = '1'
    print(' '.join(ans))

Python: #!/usr/bin/env python3
import sys
sys.setrecursionlimit(15000)
n = int(sys.stdin.readline())

ret = []
inp = sys.stdin.readlines()
G = [[0]*n for _ in range(n)]
for i in range(n):
  v = list(map(int,inp[i].split()))
  for j in v[2:]:
    G[v[0]-1][j-1] = 1
  print(" ".join(map(str,G[i])))

Python: n = int(input())

g = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
    a = list(map(int, input().split()))
    for j in range(a[1]):
        g[a[0] - 1][a[j + 2] - 1] = 1
        g[a[j + 2] - 1][a[0] - 1] = 1

for i in range(n):
    print(*g[i])

Python: v_num = int(input())
adjacent = [[0 for n in range(v_num)] for m in range(v_num)]
for _ in range(v_num):
    inp = (int(n) for n in input().split(" "))
    for i in inp[2:]:
        adjacent[inp[0] - 1][i - 1] = 1
for i in range(v_num):
    print(*adjacent[i])

Python: #演習2－10

n = int(input())
mat = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
    cmd = input().split();
    m = int(cmd[1])
    for j in range(m):
        mat[i][int(cmd[2+j])-1] = 1

for i in mat:
    print(*i)