Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100

var n int
var A [MAX + 1][MAX + 1]int

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		A[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				A[u-1][v-1] = 1

			}
		}

	}

	for i := 0; i < n; i++ {
		printList(A[i][0:n])
	}

}

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)

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

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

matrix = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    if len(a[i])>2:
        b = a[i][2:]   
        for j in b:
            matrix[i][j-1] = 1
    print(*matrix[i])

Python: from sys import stdin

X = [ 0 for i in range(100) ]
G = [[ 0 for i in range(100) ] for i in range(100)]

n = int(input())
for i in range(n) :
	X[i] = stdin.readline().strip().split()


for i in range(n) :
	for j in range(int(X[i][1])) :
		G[i][int(X[i][j+2])-1] = 1

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

Python: # Graph

N = int(input())
G = [[0]*N for i in range(N)]

for i in range(N):
    lst = list(map(int, input().split()))
    idx = lst[0]
    for j in range(lst[1]):
        G[idx-1][lst[2:][j]-1] = 1
    print(*G[idx-1])

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 = list(map(int, input().split()))
    for j in adj_list[2:]:
        adj_mat[i][j] = 1

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

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

for i in range(n):
    row = list(map(int, input().split(' ')))
    Adj[row[0] - 1] = row

for adj in Adj:
    row = [0 for i in range(n)]
    for i in adj[2:2+adj[1]]:
        row[i - 1] = 1
    print(' '.join(map(str, row)))

Python: class AdjacentGraph:
    """Implementation adjacency-list Graph.
    Beware ids are between 1 and size.
    """
    def __init__(self, size):
        self.size = size
        self._nodes = [[0] * (size+1) for _ in range(size+1)]

    def set_adj_node(self, id_, adj_id):
        self._nodes[id_][adj_id] = 1

    def __iter__(self):
        self._id = 0
        return self

    def __next__(self):
        if self._id < self.size:
            self._id += 1
            return (self._id, self._nodes[self._id][1:])

        raise StopIteration()


def run():
    n = int(input())
    g = AdjacentGraph(n)

    for i in range(n):
        id_, c, *links = [int(x) for x in input().split()]
        for n in links:
            g.set_adj_node(id_, n)

    for id_, nodes in g:
        print(" ".join([str(x) for x in nodes]))


if __name__ == '__main__':
    run()

Python: l = int(input())
rlist = []
for i in range(l):
    li = list(map(int, input().split()))
    rlist.append(li[2:])

result = []
for i in range(l):
    rcell = [0] * l
    for rl in rlist[i]:
        rcell[rl-1] = 1

    result.append(rcell)

for r in result:
    re = ''
    for rr in r:
        re += str(rr) + ' '

    print(re[:-1])

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