Go: package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	Adj := make([][]int, n)
	for i := range Adj {
		Adj[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		if k == 0 {
			continue
		}
		for i := 0; i < k; i++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			Adj[u-1][v-1] = 1
		}
	}
	for i := range Adj {
		for j := range Adj[i] {
			fmt.Printf(" %d", Adj[i][j])
			if j == n-1 {
				fmt.Println()
			}
		}
	}
}

Python: #-*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A
"""
import itertools


def input_from_txt(number=1):
    import requests
    #url = "https://judgedat.u-aizu.ac.jp/testcases/ALDS1_4_A/8/in"
    url = "https://judgedat.u-aizu.ac.jp/testcases/ALDS1_11_A/%s/in" % number
    res = requests.get(url)
    input = res.text.split("\n")
    n = int(input[0])
    Ss = []
    for i in range(n):
        S = list(map(int, input[1+i].split()))
        Ss.append(S)
    return (n, Ss)

def input_array():
    n = int(input())
    Ss = []
    for i in range(n):
        S = list(map(int, input().split()))
        Ss.append(S)
    return (n, Ss)


if __name__ == '__main__':
    (n, Ss) = input_array()
    #(n, Ss) = input_from_txt(1)
    #print(n, Ss)
    for i in range(n):
        vth = Ss[i][0]
        vd = Ss[i][1]
        adjs = Ss[i][2:]
        row = []
        for j in range(1, 1+n):
            if j in adjs: row.append(1)
            else: row.append(0)
        print(" ".join(map(str, row)))
    #ret = get_set4(S, T)
    #ret = get_set2(S, T)
    #ret = get_set(S, T)
    #print(len(ret))

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

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

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

    for i in range(n):
        line = input()
        inputs = [int(x) for x in line.split(' ')]
        u = inputs.pop(0)
        u -= 1                  # 0 オリジンへ変換
        _ = inputs.pop(0)
        for v in inputs:
            v -= 1              # 0 オリジンへ変換
            M[u][v] = 1

    for row in M:
        print(' '.join([str(x) for x in row]))


if __name__ == '__main__':
    main()

Python: import sys

N = int(input())
matrix = [[0]*N for _ in [0]*N]
for u, k, *v_a in (map(int, l.split()) for l in sys.stdin):
    for v in v_a:
        matrix[u-1][v-1] = 1

print(*(" ".join(map(str, row)) for row in matrix), sep="\n")

Python: if __name__ == '__main__':
    N = int(input())
    matrix = [['0'] * N for _ in range(N)]
    for i in matrix:
        node_info = [int(i) for i in input().split()]
        node_i = node_info[0] - 1
        if not node_info[1] == 0:
            for i in node_info[2:]:
                matrix[node_i][i - 1] = '1'
    [print(' '.join(line)) for line in matrix]

Python: def read_adj_list(n):
    al = [None for _ in range(n + 1)]
    for _ in range(n):
        u, _, *v = (int(x) for x in input().split())
        al[u] = v
    return al


def adj_list_to_matrix(n, al):
    am = [[0] * (n + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in al[i]:
            am[i][j] = 1
    return am


def print_adj_mat(n, am):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            if j > 1:
                print(" ", end="")
            print(am[i][j], end="")
        print()


def main():
    n = int(input())

    adj_list = read_adj_list(n)
    adj_mat = adj_list_to_matrix(n, adj_list)
    print_adj_mat(n, adj_mat)


if __name__ == '__main__':
    main()

Python: n = int(input())

dic = {}
for _ in range(n):
    datum = list(map(int, input().split()))
    status = ["0"]*n
    for i in datum[2:]:
        status[i-1] = "1"
    print(" ".join(status))

Python: num = int(input())
L = [[ 0 for x in range(num)] for y in range(num)]
for _ in range(num):
    c,k,*v = [int(x)-1 for x in input().split()]
    for i in v:
        L[c][i] = 1
for i in range(num):
    print( *L[i] )

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

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

Python: def resolve():
    n = int(input())
    V = [list(map(int, input().split())) for _ in range(n)]
    ans = [[0 for _ in range(n)] for _ in range(n)]
    for v, k, *a in V:
        for j in a:
            ans[v - 1][j - 1] = 1
    for a in ans:
        print(*a)


resolve()

Python: # coding: utf-8
# Your code here!

n = int(input())

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

for i in range(n):
    adj = list(map(int,input().split()))
    if adj[1] != 0:
        for j in range(2,2+adj[1]):
            ans[i][adj[j]-1] = 1
for i in range(n):
    print(*ans[i])

Python: import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    G = [[0] * n for _ in range(n)]
    for i in range(n):
        u, k, *v = map(int, input().split())
        for j in range(k):
            G[u-1][v[j]-1] = 1

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


if __name__ == '__main__':
    main()

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

for i in range(n):
	l=list(map(int,input().split()))
	u=l[0]
	k=l[1]
	for j in range(2,k+2):
		v=l[j]
		G[u-1][v-1]=1
for i in range(n):
	print(*G[i])

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

for i in range(n):
    tmp = list(map(int, input().split()))
    u = tmp[0]
    u = u -1
    k = tmp[1]
    v = tmp[2:]
    for j in range(k):
        adj[u][v[j]-1] = 1
        
for i in range(n):
        print(" ".join(list(map(str, adj[i]))))

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

for i in range(n):
    _ = list(map(int, input().split()))
    u = _[0] - 1  # 0オリジンに変換

    degree = _[1]
    for j in range(degree):
        v = _[j+2] - 1  # 0オリジンに変換
        M[u][v] = 1

for row in M:
    print(' '.join(map(str, row)))

Python: # -*- coding: utf-8 -*-
"""
Created on Fri Mar 22 16:34:05 2019

@author: Yamazaki Kenichi
"""

n = int(input())
A = [list(map(int,input().split())) for i in range(n)]

T = [[0 for i in range(n)] for i in range(n)]

for c in A:
    if c[1] != 0:
        for i in range(c[1]):
            T[c[0]-1][c[i+2]-1] = 1

for c in T:
    print(' '.join(map(str,c)))

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

n = int(input())

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

for _ in range(n):
    ls = list(map(int, input().split(" ")))
    f = ls[0]
    for i in range(ls[1]):
        adj[f - 1][ls[2 + i] - 1] = 1

for i in range(n):
    for j in range(n):
        print(adj[i][j], end="")
        if j < n - 1:
            print(" ", end="")
    print()

Python: def main():

    n = int(input())
    adj = [[0 for i in range(n)] for j in range(n)]

    for i in range(n):
        tmp = list(map(int, input().split()))
        u = tmp[0]
        u = u -1
        k = tmp[1]
        v = tmp[2:]
        for j in range(k):
            adj[u][v[j]-1] = 1

    for i in adj:
        print(*i)


if __name__ == "__main__":
    main()

Python: n = int(input())
M = [[0] * n for i in range (n)]
for i in range(n):
    u = list(map(int, input().split()))
    v = u[0]
    for j in u[2:]:
        M[v - 1][j - 1] = 1

for i in M:
    print(*i)