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
}

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: if __name__ == "__main__":
	n = int(input())
	A = [[0 for j in range(n)] for i in range(n)]
	for _ in range(n):
		command = list(map(int, input().split()))
		u = command[0]
		k = command[1]
		for l in range(k):
			v = command[l + 2]
			A[u - 1][v - 1] = 1
	for i in range(n):
		print(*A[i])

Python: n = int(input())
result = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(n):
  inp = list(map(int, input().split()))
  u, k = inp[0], inp[1]
  v = inp[2:]
  if k != 0:
    for vv in v:
      result[u-1][vv-1] = 1

result = list(result)
for i in range(n):
  print(*result[i])

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):
        print(G[i][j],end="")
        if j!=len(g[i])-1:
            print(" ",end="")
    print()

Python: V = int(input())

# 这个就不行。涉及深浅复制？
# table = [['0']*V]*V
table = [['0']*V for _ in range(V)]

for _ in range(V):
    # split 只能用于string
    # map returns a map object
    temp = list(map(int,input().split()))
    if len(temp) >= 2:
        for nei in temp[2:]:
            # print(temp[0]-1,nei-1)
            table[temp[0]-1][nei-1]='1'

for line in table:
    # join 也只能用于string
    print (" ".join(line))

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

Python: def adjmatrices():
    n = int(input())
    for i in range(n):
        node_list = list(map(int, input().split()))
        matrix = [0]*n
        for j in node_list[2:]:
            matrix[j-1] = 1
        print(*matrix)

if __name__ == '__main__':
    adjmatrices()

Python: n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]
data = [[0]*(n+1) for _ in range(n+1)]

for i in A:
    #print(i[0])
    for j in i[2:]:
        #print(j)
        data[i[0]][j] = 1

for i in data[1:]:
    for j in i[1:-1]:
        print('{} '.format(j), end='')
    print(i[-1])

Python: # Aizu Problem ALDS_1_10_B: Graph
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


n = int(input())
G = [[0 for _ in range(n)] for __ in range(n)]
for row in range(n):
    inp = [int(_) for _ in input().split()]
    a = inp[0]
    if inp[1] > 0:
        for b in inp[2:]:
            G[a-1][b-1] = 1

for row in G:
    print(' '.join([str(_) for _ in row]))

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

Python: #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin


def main():
    num = int(stdin.readline())

    for _ in xrange(num):
        L = [int(s) for s in stdin.readline().split()][2:]
        print(*(int(i in L) for i in xrange(1, num+1)))


main()

Python: n = int(input())
GM = [[0]*n for i in range(n)]

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


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

Python: def main(N,A):
    A_ans = [[0]*N for _ in range(N)]

    for i in range(N):
        for j in range(A[i][1]):
            tmp = A[i][j+2]
            #print(tmp)
            A_ans[i][tmp-1] = 1

    return A_ans

N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
A_ans = main(N,A)
for i in range(N):
    A_ans[i] = map(str,A_ans[i])
    print(' '.join(A_ans[i]))

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[0])] = 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: # -*- coding: utf-8 -*-
n = int(input())
g = []
for i in range(n):
    tmp = [int(_) for _ in input().split()[2:]]
    g.append([1 if v in tmp else 0 for v in range(1, n + 1)])

for _ in g:
    print(*_)

Python: def resolve():
    '''
    code here
    '''
    import sys

    N = int(input())
    adjacency_list = [[int(item) for item in input().split()] for _ in range(N)]

    adjacency_mat = [[0 for _ in range(N)] for _ in range(N)]

    for i, adjacency in enumerate(adjacency_list):
        if adjacency[1] != 0:
            for j in adjacency[2:]:
                adjacency_mat[i][j-1] = 1

    for item in adjacency_mat:
        print(*item)

if __name__ == "__main__":
    resolve()

Python: import sys
readline = sys.stdin.readline
write = sys.stdout.write

n = int(input())
G = [[0 for i in range(n+1)] for j in range(n+1)]
for i in range(n):
    temp = list(map(int, readline().split()))
    for j in range(temp[1]):
        G[temp[0]][temp[j+2]] = 1

for i in range(1, n+1):
    for j in range(1, n):
        write(str(G[i][j]) + " ")
    write(str(G[i][n]) + "\n")

Python: n=int(input());
G=[[0 for i in range(n)]for j in range(n)]
#print(G)
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
print(G)