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: absN = int(input())
M = [[0 for _ in range(absN)] for _ in range(absN)]

for _ in range(absN):
    cmd = list(map(int, input().split(" ")))
    for i in range(cmd[1]):
        M[cmd[0]-1][cmd[i+2]-1] = 1

for x in M:
    x =map(str, x)
    print(" ".join(x))

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

for i in range(n):
    n1, num, *cl = list(map(int, input().split()))
    for n2 in cl:
        ans[n1-1][n2-1] = 1
    print(*ans[i])

Python: n=int(input())

l=[[0 for i in range(n)] for j in range(n)]##静的確保

for i in range(n):
    p=[int(x) for x in input().split()]
    
    for j in range(n):
        if j+1 in p[2:]:
            l[i][j]=1

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

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 j in range(n)]

for i in range(n):
   info = [int(x) for x in input().split()]
   for j in info[2:]:
       a[i][j-1]=1

for v in a:
    print(*v)

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

while n:
    l = list(map(int, input().split()))
    column_g = g[l[0] - 1]
    for i in l[2:]:
        column_g[i-1] = 1
    n -= 1
for v in g:
    print(*v)

Python: n = int(input())
m = [[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:
    m[f][num] = 1

for i in range(n):
  for j in range(n):
    if(j!=n-1):
      print(m[i][j], end=' ')
    else:
      print(m[i][j])

Python: #16D8102008K Yagyu Hazuki
n=int(input())
f = [[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:
        f[u-1][each-1] = 1
for i in range(n):
    for j in range(n):
            print(f[i][j],end=' ')
    print()

Python: n = int(input())

nodes = []
for i in range(n):
    tmp_nodes = [int(x) for x in  input().split()]

    tmp = 2
    j = 1
    while j <= n:
        if j != 1:
            print(" ", end = "")
        if tmp < len(tmp_nodes) and j == tmp_nodes[tmp]:
            print(1, end = "")
            tmp += 1
        else:
            print(0, end = "")
        j += 1
        

    print("")

Python: #16D8101014F KurumeRyunosuke 2018/6/20
#import numpy as np
n=int(input())
#ls=np.zeros((n,n))
ls=[[0] * n] * n
for i in range(n):
	tmp=input().split()
	for j in range(int(tmp[1])):
		#print("*")
		ls[i][int(tmp[j+2])-1]=1


for i in range(n):
    for j in range(n):
        if(j!=n-1):
            print(int(ls[i][j]), end=' ')
        else:
            print(int(ls[i][j]))

Python: n = int(input())

for i in range(n):
    matrix = [str(0)]*n
    a = list(map(int, input().split()))
    if len(a) > 2:
        for j in a[2:]:
            matrix[j-1] = str(1)
    print(' '.join(matrix))

Python: N = int(input())
G = [[0] * N for _ in range(N)]

for _ in range(N):
    u, n, *K = map(int, input().split())
    u -= 1
    for k in K:
        k -= 1
        G[u][k] = 1

for g in G:
    print(*g)

Python: n=int(input())
v=[]
u=0
e=0

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

for i in range(n):
    S=input().split()
    if S[1]!=0:
        for j in range(int(S[1])):
            A[i][int(S[2+j])-1]=1

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

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

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()