Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	g := make([][]int, n)

	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
	}

	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		u--
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			v--
			g[u][v] = 1
		}
		fmt.Fprintln(writer, joinint(g[u], " "))
	}

	writer.Flush()
}

func joinint(a []int, sep string) string {
	n := len(a)
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		ss[i] = fmt.Sprintf("%d", a[i])
	}
	return strings.Join(ss, sep)
}

Python: 
n=int(input())

arr = [[0 for i in range(n)] for j in range(n)]
#for i in arr:
    #print(' '.join(map(str, i)))

#print(arr)

for i in range(0,n):
    l=raw_input().split()
    if(int(l[1])>=1):
        x=int(l[0])
        y=int(l[1])
        p=len(l)
        d=0
        while(2+d<p):
            z=int(l[2+d])
            #print(x,y,z)
            arr[x-1][z-1]=1
            #print(arr)
            d=d+1

#print(arr)
for i in arr:
    print(' '.join(map(str, i)))

Python: #16D8102008K Yagyu Hazuki
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
print(dp)

Python: N=int(input())
ad_ma=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
    nums=list(map(lambda x:int(x)-1,input().split()))
    f=nums[0]
    nums=nums[2:]
    for num in nums:
        ad_ma[f][num]=1
 
  
for i in range(N):
    for j in range(N):
        if(j!=N-1):
            print(ad_ma[i][j],end=' ')
        else:
            print(ad_ma[i][j])

Python: n = int(input())
adj = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
    l = list(map(int, input().split()))
    if l[1] == 0:
        print(' '.join(list(map(str, adj[i]))))
        # continue
    else:
        for j in range(2,len(l)):
            adj[l[0]-1][l[j]-1] = 1
        print(' '.join(list(map(str, adj[i]))))
# for i in range(n):
    # print(' '.join(list(map(str, adj[i]))))

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

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

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

Python: if __name__ == '__main__':
    n = int(input())
    graph = [[0 for i in range(n)] for _ in range(n)]
    for i in range(n):
        datas = [int(num) for num in input().split(' ')]
        if datas[1] > 0:
            for j in datas[2:]:
                graph[datas[0] - 1][j - 1] = 1

    for row in graph:
        print(str(row).replace(',', '').replace('[', '').replace(']', ''))

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

Python: n=int(input())
for _ in [0]*n:
    a=[0]*n
    for i in list(map(int,input().split()))[2:]:a[i-1]=1
    print(*a)

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)