Problem:
Graph There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V|]$ of $|V|$ lists, one for each vertex in $V$. For each $u \in V$, the adjacency list $Adj[u]$ contains all vertices $v$ such that there is an edge $(u, v) \in E$. That is, $Adj[u]$ consists of all vertices adjacent to $u$ in $G$. An adjacency-matrix representation consists of $|V| \times |V|$ matrix $A = a_{ij}$ such that $a_{ij} = 1$ if $(i, j) \in E$, $a_{ij} = 0$ otherwise. Write a program which reads a directed graph $G$ represented by the adjacency list, and prints its adjacency-matrix representation. $G$ consists of $n\; (=|V|)$ vertices identified by their IDs $1, 2,.., n$ respectively. Input In the first line, an integer $n$ is given. In the next $n$ lines, an adjacency list $Adj[u]$ for vertex $u$ are given in the following format: $u$ $k$ $v_1$ $v_2$ ... $v_k$ $u$ is vertex ID and $k$ denotes its degree. $v_i$ are IDs of vertices adjacent to $u$. Output As shown in the following sample output, print the adjacent-matrix representation of $G$. Put a single space character between $a_{ij}$. Constraints  $1 \leq n \leq 100$  Sample Input 4
1 2 2 4
2 1 4
3 0
4 1 3 Sample Output 0 1 0 1
0 0 0 1
0 0 0 0
0 0 1 0

Solution (Python):

"""
Created on Sun Jul  8 09:32:48 2018

@author: maezawa
"""

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

for j in range(n):
    ain = list(map(int, input().split()))
    u = ain[0]
    k = ain[1]
    for i in range(k):
        adj[u-1].append(ain[i+2]-1)
    
    
for j in range(n):
    for k in adj[j]:
        a[j][k] = 1
for i in range(n):
    print(*a[i], sep=' ')

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

for i in range(n):
    a=list(map(int,input().split()))
    y=a[1]
    if y!=0:
        for j in range(2,2+y):
            r[i][a[j]-1]=1

for i in range(n):
    for j in range(n):
        if j!=0:
            print(" ",end="")
        print(r[i][j],end="")
    print("\n",end="")

Solution (Python):

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

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

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

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

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

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

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

Solution (Python):
n = int(input())
A = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
    V = [int(i) for i in input().split()]
    for j in V[2:]:
        A[i][j-1] = 1
for i in A:
    tmp =""
    for j in i:
        tmp+=str(j) + " "
    print(tmp[:-1])

Solution (Python):
N = int(input())
adj = [[0 for j in range(N)] for i in range(N)]
for _ in range(N):
    u, k, *v = input().split()
    for i in v:
        adj[int(u)-1][int(i)-1] = 1

for a in adj:
    print(" ".join(map(str, a)))

Solution (Python):



n=int(input())
graph=[[0]*n for loop in range(n)]
for loop in range(n):
    tmp_ope=list(map(int,input().split()))
    for j in range(tmp_ope[1]):
        graph[tmp_ope[0]-1][tmp_ope[j+2]-1]=1

for loop in range(n):
    for j in range(0,n-1):
        print(f"{graph[loop][j]}",end=" ")
    print(f"{graph[loop][n-1]}")

Solution (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):
    print(" ".join(matrices[i]))

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

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

for row in A:
    msg = ' '.join(map(str, row))
    print(msg)

Solution (Python):


import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

N=INT()
G=[[0]*N for i in range(N)]
for i in range(N):
    l=LIST()
    u=l[0]
    l=l[2:]
    for v in l:
        G[u-1][v-1]=1

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

Solution (Python):
n = int(input())

Adj = [ [] for _ in range(n) ]
V = []

for i in range(n):
    V = list(map(int, input().split()))
    for i in range(V[1]):
        Adj[V[0]-1].append(V[2+i])

G = [ [0]*n for _ in range(n) ]

for i in range(n):
    for j in Adj[i]:
        G[i][j-1] = 1

    print(*G[i])

Solution (Python):
n = int(input())
A = [[0 for i in range(n)] for i in range(n)]
for _ in range(n):
    u, k, *v = [int(i) for i in input().split()]
    for vi in v:
        A[u-1][vi-1] = 1

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

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

Solution (Python):
class Graph:
    def __init__(self):
        self.edges = {}

    def addVertex(self, v):
        if v not in self.edges:
            self.edges[v] = []

    def addEdge(self, from_v, to_v):
        if from_v not in self.edges:
            self.edges[from_v] = []
        if to_v not in self.edges[from_v]:
            self.edges[from_v].append(to_v)

    def isEdge(self, from_v, to_v):
        if to_v not in self.edges:
            return False
        return to_v in self.edges[from_v]

g = Graph()
n = int(input())
for i in range(n):
    u, k, *v = map(int, input().split())
    g.addVertex(u)
    for j in v:
        g.addEdge(u, j)

adj = []
for i in range(1, n+1):
    e = []
    for j in range(1, n+1):
        if g.isEdge(i, j):
            e.append(1)
        else:
            e.append(0)
    adj.append(e)

for a in adj:
    print(" ".join(map(str, a)))

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

Solution (Python):
n = int(raw_input())
x = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	seq = map(int,raw_input().split())
	tmp = seq[0]-1
	n2 = seq[1]
	if n2!=0:
		for e in seq[2:]:
			x[tmp][e-1]=1
for i in range(n):
	print " ".join(map(str,x[i]))

Solution (Python):
n = int(raw_input())
mat = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
    ls = map(int,raw_input().split())
    u = ls[0]
    k = ls[1]
    for m in range(k):
        mat[u-1][ls[2+m]-1] = 1
for item in mat:
    print ' '.join(map(str,item))

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

Solution (Python):



import sys

size = int(sys.stdin.readline().strip())
matrix = [0] * (size * size)

for _ in range(0, size):
    vals = [int(x) for x in sys.stdin.readline().strip().split(' ')]
    if vals[1] == 0: continue
    idx = vals[0] - 1
    for i in range(0, vals[1]):
        av_idx = vals[2 + i] - 1
        matrix[size * idx + av_idx] = 1

for i in range(0, size):
    str_ = ''
    for j in range(0, size):
        str_ += '%d' % matrix[size * i + j]
        if j != size - 1:
            str_ += ' '
    print str_

Solution (Python):
n=int(raw_input())

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


for i in range(n):
	a=list(map(int,raw_input().split()))
	if a[1]>0:
		for j in range(2,len(a)):
			arr[i][a[j]-1]=1
for i in range(n):
	for j in range(n):
		print arr[i][j],
	print

Solution (Python):
import sys

if __name__ == "__main__":
    lines = sys.stdin.readlines()

    
    dimension = int(lines[0])
    matrix = []
    for x in range(dimension):
        matrix.append([0] * dimension)

    
    for index, line in enumerate(lines[1:]):
        for edge in [int(x) for x in line.strip().split(" ")[2:]]:
            matrix[index][edge - 1] = 1

    
    for row in matrix:
        print(" ".join([str(x) for x in row]))

Solution (Python):
n = int(raw_input())
graph = [[0 for i in xrange(n)] for j in xrange(n)]

for i in xrange(n):
	fffff = map(int,raw_input().split())
	y = fffff[0] - 1
	for j in xrange(fffff[1]):
		graph[y][fffff[j + 2] - 1] = 1
		
for i in xrange(n):
	print " ".join(map(str, graph[i]))

Solution (Python):
n = int(raw_input())
for i in range(n):
    entry = map(int, raw_input().strip().split(' '))
    u = entry[0]
    k = entry[1]
    neighbors = set(entry[2:])
    for j in range(1,n+1):
        if j in neighbors:
            print 1,
        else:
            print 0,
    print

Solution (Python):

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

Solution (Python):
import sys

N = int(raw_input())
A = [0] * N
for i in range(N):
  A[i] = [0] * N

for line in sys.stdin:
  values = line.split()
  u = int(values[0]) - 1
  k = int(values[1])
  nodes = values[2:]
  for i in range(int(k)):
    v = int(nodes[i]) - 1
    A[u][v] = 1

for i in range(N):
  print " ".join([str(x) for x in A[i]])

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

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

for v in g:
    print(*v)

Solution (Python):
n = int(input())
mat = [[0] * n for _ in range(n)]
for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    for j in adj[2:]:
        mat[i - 1][j - 1] = 1
for m in mat:
    print(' '.join(map(str, m)))

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

Solution (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:])

Solution (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:])

Solution (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:])

Solution (Python):
n = int(input())

adj_mat = [[0] * (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:])

Solution (Python):
import sys

def list2mat(V, n):
    M = [[0] * (n) for _ in range(n)]
    for i in range(1, n + 1):
        for v in V[i]:
            M[i - 1][v - 1] = 1
    return M

lines = sys.stdin.readlines()
n = int(lines[0])
V = [[0] for _ in range(n + 1)]

for i in range(1, n + 1):
    v = map(int, lines[i].split())
    V[v[0]] = v[2:]

M = list2mat(V, n)
for m in M:
    print " ".join(map(str, m))

Solution (Python):
import sys,re

d = int(sys.stdin.readline().strip())

for line in sys.stdin:
    cols = line.strip().split(' ')
    out = [ "0" for i in range(d) ]
    for n in cols[2:]:
        out[int(n)-1]="1"
    print " ".join(out)

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

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

Solution (Python):
n = int(input())
v = [[0]*n  for _ in range(n)]
for i in range(n):
  l = list(map(int,input().split()))
  u = l[0]
  k = l[1]
  c = l[2:]
  for j in c:
    v[u-1][j-1]=1
for m in v:
    print(' '.join(map(str, m)))

Solution (Python):
n = int(input())

l = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n + 1):
    if i == 0:
        continue
    u = list(map(int, input().split()))
    for x in u[2:]:
        l[i][x] = 1

for i in range(n + 1):
    if i == 0:
        continue
    print(*l[i][1:])

Solution (Python):


level = False
def debug(v):
    if level:
        print(v)

n = int(input())
a = []

for i in range(n):
    v = input().split()
    v.pop(0)
    v.pop(0)
    a.append([int(x) for x in v])

debug(a)

for i in range(0, n):
    v = a[i]
    for j in range(n):
        if (j + 1) in v:
            print(str(1), end="")
        else:
            print(str(0), end="")
        if j != n - 1:
            print(" ", end="")
    print()

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

Solution (Python):




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])
    adj_matrix = [[0] * vertex_num for _ in range(vertex_num)]
    vertex_info = list(map(lambda x: x.split(), _input[1:]))
    

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

Solution (Python):




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

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

Solution (Python):




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

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

Solution (Python):




import sys


def generate_graph(v_info):
    for info in v_info:
        adj_info = info[2:]
        assert len(adj_info) == int(info[1])
        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)]
    

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

Solution (Python):

def Graph(n,A):
    ans=[]
    for i in range(n):
        line=[]
        for j in range(n):
            line.append(0)
        ans.append(line)
    for i in range(n):
        if A[i][1]!=0:
            for j in range(A[i][1]):
                ans[i][A[i][2+j]-1]=1
    for i in range(n):
        for j in range(n):
            ans[i][j]=str(ans[i][j])
        print(" ".join(ans[i]))
 
 
if __name__=="__main__":
    n=int(input())
    A=[]
    for i in range(n):
        A.append(list(map(int,input().split(" "))))
    Graph(n,A)

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

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

Solution (Python):
if __name__ == '__main__':
    
    num = int(input())
    data = []
    for _ in range(num):
        data.append(list(map(int, input().split(' '))))

    
    graph_table = [[0]*num for _ in range(num)]
    for d in data:
        node_id = d[0]
        num_of_e = d[1]
        for e in d[2:]:
            graph_table[node_id-1][e-1] = 1

    
    for row in graph_table:
        print(*row)

Solution (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]

Solution (Python):
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    n = int(input())
    edge = [[0]*n for i in range(n)]

    for i in range(n):
        u, k, *vs = [int(j) - 1 for j in input().split()]
        
        for v in vs:
            edge[u][v] = 1

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

    pass

if __name__ == '__main__':
    solve()

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

Solution (Python):
import sys


class Graph:
    def __init__(self, nodes={}):
        self.nodes = nodes


n = int(input())
G = Graph()
for line in sys.stdin:
    numList = list(map(int, line.split()))
    G.nodes[numList[0]] = list(numList[2:])
for node in range(n):
    out = ''
    for adj in range(n):
        if adj + 1 != n:
            out += '1 ' if adj + 1 in G.nodes[node + 1] else '0 '
        else:
            out += '1' if adj + 1 in G.nodes[node + 1] else '0'
    print(out)

Solution (Python):
n = int(raw_input())                                           
GMatrix = [[0]*n for i in range(n)]                            
GList = {}                                                     
                                                               
for i in range(n):                                             
    input = map(int, raw_input().split())                      
    GList[i] = input[2:]                                       
    for j in input[2:]:                                        
        GMatrix[i][j-1] = 1                                    
                                                               

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

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

Solution (Python):

N = int(input())


ans = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    a = list(map(int, input().split()))
    id = a[0]
    jisu = a[1]
    for j in range(jisu):
        c = a[j+2]
        ans[i][c-1] = 1

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

Solution (Python):

"""
Main??????????????????
"""

N = int(input())


nodes = [[0 for i in range(N)] for j in range(N)]


for i in range(N):
    j = list(map(int, input().split())) 
    no = j[0] - 1                       
    childNos = j[2:]                    

    for j in range(len(childNos)):
        childNo = childNos[j] - 1
        nodes[no][childNo] = 1



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

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

for _ in range(n):
  V = list(map(int, input().split()))
  u = V[0]
  for v in V[2:]:
    G[u - 1][v - 1] = 1

for i in G:
  print(*i)

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

for i in range(n):
    u = list(map(int, input().split()))
    if u[1] > 0:
        for i in u[2: 2 + u[1]]:
            Adj[u[0] - 1][i - 1] = 1

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

Solution (Python):
n=int(input())
V=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
	v=[int(j) for j in input().split(" ")]
	u=v.pop(0)
	k=v.pop(0)
	for j in range(k):
		V[u-1][v[j]-1]=1



for i in range(n):
	print(" ".join([str(j) for j in V[i]]))

Solution (Python):
def convertList(G):
    n = len(G)
    GL = [ [0 for _ in range(n)] for _ in range(n)]
    for key, values in G.items():
        GL[key - 1][key - 1] = 0
        for v in values:
            GL[key - 1][v - 1] = 1

    return GL


if __name__ == '__main__':
    G = {}
    n = int(input())
    for _ in range(n):
        tmp = list(map(int, input().split()))
        u = tmp.pop(0)
        k = tmp.pop(0)
        G[u] = tmp
    GL = convertList(G)
    for i in range(n):
        print(*GL[i])

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

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

Solution (Python):
from sys import stdin
n = int(stdin.readline())
v = [[0] * (n + 1) for i in range(n + 1)]
for u in range(1, n + 1):
    U = [int(j) for j in stdin.readline().split()]
    for k in U[2:]:
        v[u][k] += 1
for i in range(1, n + 1):
    print(*v[i][1:])

Solution (Python):
from sys import stdin
n = int(stdin.readline())
v = [[0] * n for _ in range(n)]
for u in range(n):
    l = list(map(int, stdin.readline().split()))
    for k in l[2:]:
        v[u][k - 1] = 1
    print(*v[u])

Solution (Python):
from sys import stdin
n = int(stdin.readline())
v = [[0] * n for _ in range(n)]
for u in range(n):
    l = [int(j) for j in stdin.readline().split()]
    for k in l[2:]:
        v[u][k - 1] = 1
    print(*v[u])

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

Solution (Python):


n = int(input())
M = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(n):
    u, k, *v = map(int, input().split())
    u = u-1 
    if k == 0:
        continue
    for num in v:
        num = num-1 
        M[u][num] = 1
for row in M:
    print(*row)

Solution (Python):
n = int(raw_input())
a = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
    tmp = map(int, raw_input().split())
    if tmp[1]:
        for j in range(1, tmp[1]+1):
            a[i][tmp[j+1]-1] = 1
for i in range(n):
    print ' '.join(map(str, a[i]))

Solution (Python):
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):
    print(*dp[i][:])

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

Solution (Python):


N = int(input())
adj = [["0"]*N for _ in range(N)]

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

for a in adj:
    print(" ".join(a))

Solution (Python):

n = int(input().rstrip())

for i in range(n):
    line = input().rstrip().split(" ")
    lineMax = int(line[1])
    lineIndex = 0
    for j in range(n):
        if lineIndex >= lineMax:
            print(0, end = "")
        else:
            if j + 1 == int(line[lineIndex + 2]):
                print(1, end = "")
                lineIndex += 1
            else:
                print(0, end = "")
        if j + 1 != n:
            print(" ", end ="")
    print()

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

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

Solution (Python):


import sys, math, os


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

Solution (Python):



n=int(input())
L=[]
for i in range(n):
    L.append([])
    for j in range(n):
        L[i].append("0")

for i in range(n):
    v=[int(i) for i in input().split()]

    for j in range(2,2+v[1]):
        L[v[0]-1][v[j]-1]="1"

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

Solution (Python):
def main():
    num = int(input())
    T = [[0] * num for i in range(num)]
    for n in range(num):
        a = list(map(int,input().split()))
        u = a[0] - 1
        if a[1] > 0:
            for i in a[2:]:
                T[u][i-1] = 1

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

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n = input()
    Adj = [[0]*n for m in xrange(n)]
    for i in xrange(n):
        a = map(int,raw_input().split())
        for j in xrange(a[1]):
            Adj[i][a[2:][j]-1] = 1

    for i in xrange(n):
        for j in xrange(n):
            if j == n-1:
                print Adj[i][j]
            else:
                print Adj[i][j],

if __name__ == '__main__':
    main()

Solution (Python):
if __name__ == '__main__':
    N = input()

    m = [[0] * N for i in range(N)]

    for i in range(N):
        v = map(int, raw_input().split())
        for j in v[2:]:
            m[i][j-1] = 1

    for row in m:
        for i in row:
            print i,
        print

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

Solution (Python):
n = int(raw_input())
G = [[0 for i in xrange(n)] for j in xrange(n)]

for i in xrange(n):
    data = map(int, raw_input().split())
    u = data[0]-1
    k = data[1]
    for j in xrange(k):
        v = data[j+2]-1
        G[u][v] = 1

for i in xrange(n):
    print " ".join([str(x) for x in G[i]])

Solution (Python):

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


graph_table = [[0]*n for i in range(n)]


for d in data:
    node_id = d[0]
    num_of_e = d[1]
    for e in d[2:]:
        graph_table[node_id-1][e-1] = 1


for g in graph_table:
    print(*g)

Solution (Python):
n = int(input())
A = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(n):
    tmp_u = list(map(int, input().split()))
    vs = tmp_u[2:]
    for v in vs: 
        A[tmp_u[0]-1][v-1] = 1
       
for i in range(n):
    tmp_A = A[i]
    tmp_A = map(str, tmp_A)
    tmp_A = ' '.join(tmp_A)
    print(tmp_A)

Solution (Python):
v_num = int(input())
adjacent = [[0 for n in range(v_num)] for m in range(v_num)]
for _ in range(v_num):
    inp = [int(n) for n in input().split(" ")]
    for i in inp[2:]:
        adjacent[inp[0] - 1][i - 1] = 1
for i in range(v_num):
    print(*adjacent[i])

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

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

Solution (Python):

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

a=[[0 for i2 in range(n)]for i1 in range(n)]

for i in range(n):
    for j in range(adj[i][1]):
        a[i][adj[i][j+2]-1]=1

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

Solution (Python):
n = int(input())
a = [[0 for i in range(n)] for j 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
    print(*a[u - 1])

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

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

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

Solution (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] - 1
    for j in v[2:]:
        a[u][j - 1] = 1
  
for i in a:
    print(*i)

Solution (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] - 1
    for j in v[2:]:
        a[u][j - 1] = 1
    print(*a[i])

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