Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		arr[u-1] = make([]int, n)
		for j := 0; j < k; j++ {
			n := scanInt()
			arr[u-1][n-1] = 1
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for _, col := range arr {
		fmt.Fprintln(w, strings.Trim(fmt.Sprint(col), "[]"))
	}
	w.Flush()
}

Python: N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]

class Graph:
    def __init__(self,Vertex,Edge):
        self.V = Vertex
        self.E = Edge

Edge = [i+1 for i in range(N)]
Vertex = []
for i in range(N):
    for j in range(2,A[i][1]+2):
        Vertex.append((A[i][0],A[i][j]))

g = Graph(Vertex,Edge)

R = [[0 for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(N):
        if (i+1,j+1) in g.V:
            R[i][j] = 1

for i in range(N):
    for j in range(N):
        if j >= 1:
            print(" ",end="")
        print(R[i][j],end="")
    print()

Python: from sys import stdin
from collections import deque

def print_2d_array(A):
    for i in range(1, len(A)):
        print(*A[i][1:], sep=" ")

def read_and_print_graph(n):
    A = [ [0]*(n+1) for _ in range(n+1) ]
    for _ in range(n):
        line = deque(stdin.readline().strip().split())
        i = line.popleft()
        line.popleft()
        for k in line:
            A[int(i)][int(k)] = 1
    print_2d_array(A)

n = int(input())
read_and_print_graph(n)

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys


def generate_graph(v_info):
    for info in v_info:
        adj_info = info[2:]
        for each in adj_info:
            adj_matrix[int(info[0]) - 1][int(each) - 1] = 1
    return adj_matrix


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertex_num = int(_input[0])
    vertex_info = list(map(lambda x: x.split(), _input[1:]))
    adj_matrix = [[0] * vertex_num for _ in range(vertex_num)]
    # assert len(vertex_info) == vertex_num

    ans = generate_graph(vertex_info)
    for v_result in ans:
        print(*v_result)

Python: # https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/11/ALDS1_11_A
# やるだけ
# 有向成分を読み込むたびにノード番号に対応する表に書き込んでいけばよい

N = int(input())
for _ in range(N):
    out_ls = [0]*N
    tmp = list(map(int, input().split()))
    # id = tmp[0]-1 #idは順番通り与えられるので実はこれもいらない
    if tmp[1] != 0:
        for adj in tmp[2:]:
            out_ls[adj-1] = 1

    print(*out_ls)

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

Python: n = int(input())

adj_mat = [[0 for i in range(n + 1)] for j in range(n)]

for i in range(n):
    listed_input = list(map(int, input().split()))
    for j in listed_input[2:]:
        adj_mat[i][j] = 1

for adj_list in adj_mat:
    print(*adj_list[1:])

Python: import sys
input = sys.stdin.readline

def main():
    n = int(input())
    G = [[0]*n for _ in range(n)]
    for _ in range(n):
        a = list(map(int, input().split()))
        u = a[0] - 1
        k = a[1]
        for i in range(k):
            v = a[2+i] - 1
            G[u][v] = 1
    for g in G:
        print(' '.join(list(map(str, g))))

if __name__ == '__main__': main()

Python: #16D8101014F KurumeRyunosuke 2018/6/20
import numpy as np
n=int(input())
ls=np.zeros((n,n))
for i in range(n):
	tmp=input().split()
	#print(tmp)
	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: def main():
    n = int(input())
    rows = []
    for i in range(n):
        rows.append([int(x) for x in input().split()])
    for row in rows:
        u,k = row[0],row[1]
        ul = [0]*n
        for j in range(k):
            ul[row[j+2]-1] = 1
        print(' '.join([str(u) for u in ul]))

if __name__ == '__main__':
    main()

Python: n = int(input())
M = [["0"]*n for _ in range(n)]
for _ in range(n):
    i = [int(i) for i in input().split()]
    u = i[0]
    k = i[1]
    V = i[2:]
    for v in V: M[u-1][v-1] = "1"
for i in M: print(*i)

Python: n=int(input())

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

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])
            arr[x-1][z-1]=1
            d=d+1

print(arr)

Python: class Node:
    def __init__(self, num, deg, neib):
        self.num = num
        self.deg = deg
        self.neib = neib


dnum = int(input())
N = []
for i in range(dnum):
    data = input().split()
    
    u = int(data[0])
    k = int(data[1])
    if k > 0:
        v = list(map(int, data[2:]))
        node = Node(u,k,v)
    else:
        node = Node(u,k,0)

    N.append(node)

O = []
for e in N:
    out = [0]*dnum
    if e.neib != 0:
        for j in e.neib:
            out[j-1] = 1
    else: pass

    O.append(out)

for i in O:
    print(*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[numList[1]] = 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())
ans = []
for i in range(N):
    a = list(map(int, input().split()))
    pre = [0 for _ in range(N)]
    for k in a[2:]:
        pre[k-1] = 1
    ans.append(pre)
for i in range(N):
    print(' '.join(list(map(str, ans[i]))))

Python: n=int(input())
da=[[0 for i in range(n)] for i in range(n)]
for i in range(n):
    se=list(map(int,input().split()))
    for j in se[2:]:
        da[i][j-1]=1
for i in range(n):
    for j in range(n):
        if j==n-1:
            print(da[i][j])
        else:
            print(da[i][j],end=' ')

Python: n = int(input())

adj_mat = [[0 for i in range(n + 1)] for j in range(n)]

for i in range(n):
    adj_list_i = list(map(int, input().split()[2:]))
    for j in adj_list_i:
        adj_mat[i][j] = 1

for r in adj_mat:
    print(*r[1:])

Python: n = int(input())

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

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

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

for i in range(n):
  a = A[i][0]
  j = A[i][1]
  if j != 0:
    for k in range(j):
      b = A[i][k+2]
      B[a-1][b-1] = 1

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

Python: import sys
def main():
    n = int(input())
    lines = sys.stdin.readlines()
    outputs = [None] * n
    str_range = [str(i) for i in range(1, n+1)]
    for i in range(n):
        idx, idx_n, *idx_vertices = lines[i].rstrip().split()
        outputs[i] = ['1' if str_i in idx_vertices else '0' for str_i in str_range]

    [print(" ".join(outputs[i])) for i in range(n)]


main()

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

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

for _ in range(N):
    l = list(map(int, input().split()))
    u, k = l.pop(0), l.pop(0)
    
    row = A[u-1]
    for x in l:
        row[x-1] = 1

for row in A:
    print(*row)

Python: n = int(input())
ans = list()
for i in range(n):
    tmp = list()
    for j in range(n):
        tmp.append(0)
    ans.append(tmp)

for i in range(n):
    l = [int(i) for i in input().split()]
    for li in l[2:]:
        # print(i, li)
        ans[i][li - 1] = 1

for i in ans:
    print(" ".join([str(x) for x in i]))