Go: package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	graph := make([][]int, N)
	for i := range graph {
		graph[i] = make([]int, N)
		var u, k int
		fmt.Scan(&u, &k)
		for j := 0; j < k; j++ {
			var v int
			fmt.Scan(&v)
			v--
			graph[i][v] = 1
		}
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(graph[i][j])
		}
		fmt.Println()
	}
}

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)

Python: n=int(input()) #รับจำนวน node ทั้งหมด
m=[[0]*n for i in range(n)] #สร้าง array matrix 0 ขนาดเท่าจำนวน node

for i in range(n):
    tmp=list(map(int,input().split())) #วน loop ตามจำนวน node รับค่าข้อมูลแต่ละ node
    #ตน 0 คือ node , ตน 1 คือ จำนวน vertex ตน 2 เป็นต้นไปคือ vertex
    for j in tmp[2:]:
        m[i][j-1]=1
    #แสดงผล node และ vertex ที่มีความสัมพันธ์กัน ใส่ 0 เมื่อไม่เกิดความสัมพันธ์ ใส่ 1 เมื่อเกิด
    #Show เป็น Matrix    
for i in range(n):
    print(" ".join(list(map(str,m[i]))))

Python: n=int(input())
g=[[0 for i in range(n)]for j in range(n)] 
for i in range(n):
    s=input()
    l=s.split()
    for i in range(len(l)):
        l[i]=int(l[i])
    for i in l[2:]:
        g[l[0]-1][i-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: def conv_list(n):
    adj_matrix = []
    for _ in range(n):
        adj_list = input().split()
        adj_list = list(map(int, adj_list))
        adj_row = [0] * n
        if adj_list[1] > 0:
            for i in adj_list[2:]:
                adj_row[i - 1] = 1
        adj_matrix.append(adj_row)
    return adj_matrix


def main():
    n = int(input())
    adj_matrix = conv_list(n)
    for row in adj_matrix:
        print(" ".join(map(str, row)))


if __name__ == "__main__":
    main()

Python: def main():
    n = int(input())
    m = [[0] * n for _ in range(n)]
    for _ in range(n):
        u, k, *v = map(int, input().split())
        for i in range(k):
            m[u - 1][v[i] - 1] = 1
    for row in m:
        print(' '.join(map(str, row)))


if __name__ == '__main__':
    main()

Python: n = int(input())
for i in range(n):
    u, k, *v = map(int, input().split())
    row = ""
    for j in range(1, n + 1):
        if j in v:
            row += "1"
        else:
            row += "0"
        if j != n:
            row += " "
    print(row)

Python: import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    n = int(input())
    edge = []
    for i in range(n):
        u,k,*v_li = map(int,input().split())
        u-= 1
        for j in range(len(v_li)):
            v_li[j] -= 1
        edge.append(v_li)
    ans_edge = [[0]*n for j in range(n)]
    
    for j in range(len(edge)):
        for k in range(len(edge[j])):
            ans_edge[j][edge[j][k]] = 1
    for j in range(len(ans_edge)):
        print(*ans_edge[j])

Python: import sys


if __name__ == "__main__":
    n = int(sys.stdin.readline())
    ANS = [[0] * n for i in range(n)]
    for inp in sys.stdin.readlines():
        inp = list(map(int, inp.split()))
        for i in inp[2:]:
            ANS[inp[0]-1][i-1] = 1
    for row in ANS:
        print(" ".join(map(str, row)))