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

n = int(input())
Ans =[ [0 for i in range(n)] for j in range(n)]
for l in range(n):
  raw = list(map(int,input().split()))
  i = raw[0]
  d = raw[1]
  for m in range(2,d+2):
    Ans[i-1][raw[m]-1] = 1

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

Solution (Python):



if __name__ == '__main__':

    n = int(input())
    M = [[0 for i in range(n)] for j in range(n)]
    for _ in range(n):
        l = list(map(int, input().split(" ")))
        u = l[0]
        k = l[1]
        if k != 0:
            for v in l[2:]:
                M[u-1][v-1] = 1
        
    for r in M:
        print(" ".join(map(str, r)))

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

Solution (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:
    k = adj[1]
    E = adj[2:2+k]
    row = [0 for i in range(n)]
    for i in E:
        row[i - 1] = 1
    print(' '.join(map(str, row)))

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

Solution (Python):
import sys
data_list = []
for line in sys.stdin:
	data_list.append(line.split())

class Node():
    def __init__(self, name, transaction_list = None):
        self.transaction_list = transaction_list or []

    def add_node(self, node):
        self.transaction_list.append(node)

def convert_adjencentList_to_adjencentMatrix(adjencentList):
    adjencent_matrix = [[0 for i in range(len(adjencentList))] for j in range(len(adjencentList))]
    count = 0
    for targetList in adjencentList:
        targetList.transaction_list.sort()
        for target_index in targetList.transaction_list :
            adjencent_matrix[count][int(target_index) - 1] = 1
        count = count + 1

    for i in adjencent_matrix:
        print(*i)

if __name__ == "__main__":
        node_data_list = []

        for node_data in data_list[1:]:
            node = Node(node_data[1])
            for transaction_node in node_data[2:]:
                node.add_node(transaction_node)

            node_data_list.append(node)

        convert_adjencentList_to_adjencentMatrix(node_data_list)

Solution (Python):
N=int(input())
M=[[0]*N for _ in[0]*N]
for e in[list(map(int,input().split()))for _ in[0]*N]:
 for v in e[2:]:M[e[0]-1][v-1]=1
for r in M:print(*r)

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

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

g = [[0 for _ in range(n)] for _ in range(n)]

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

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

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

for li in A:
    print(' '.join(list(map(str, li))))

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

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

m = [[0 for _ in range(n)] for _ in range(n)]

for _ in range(n):
    tmp = [int(x) for x in input().split()]
    u = tmp[0]
    k = tmp[1]
    l = tmp[2:]
    for x in l:
        m[u-1][x-1] = 1

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

Solution (Python):
import sys
n = int(input())
input_lines = [[int(i) for i in lines.split()] for lines in sys.stdin.read().splitlines()]
for i in range(n):
    out_list = ['0'] * n
    m = len(input_lines[i])
    for j in range(m-1, 1, -1):
        out_list[input_lines[i][j]-1] = '1'
    print(' '.join(out_list))

Solution (Python):
def main():
    n = int(input())
    m = [[0 for j in range(n+1)] for i in range(n+1)]

    for i in range(n):
        d = list(map(int, input().split()))
        for j in range(2, len(d)):
            m[d[0]][d[j]] = 1

    for i in range(1, n+1):
        print(" ".join([str(m[i][j]) for j in range(1, len(m[i]))]))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
adm = []
for i in range(n):
    x = list(map(int,input().split()))
    tmp = [0]*n
    if x[1] == 0:
        adm.append(tmp)
    else:
        a = x[2:]
        for j in a:
            tmp[j-1] = 1
        adm.append(tmp)
for i in range(len(adm)):
    print(*adm[i])

Solution (Python):



Al=[]
n=int(input())
for i in range(n):
    a=list(map(int,input().split()))
    Al.append(a[2:])
Am=[[0 for j in range(n)]for i in range(n)]

for i in range(n):
    for k in Al[i]:
            Am[i][k-1]=1
for i in range(n):
    print(*Am[i])

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

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

Solution (Python):
n=int(input())
G=[[0 for i in range(n)]for j in range(n)]
u=[0 for i in range(n)]
for i in range(n):
    A=input().split()
    u[i]=int(A[0])
    k=int(A[1])
    for j in range(k):
        x=int(A[j+2])-1
        G[i][x]=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):
n = int(input())
B = [[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(A[1]):
        B[A[0]-1][A[j+2]-1] = 1

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

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

Solution (Python):
def main():
    n=int(input())
    v=[]
    array=[]
    for i in range(n):
        zero=[0 for i in range(n)]
        a=list(map(int,input().split()))
        a=a[2:]
        for j in a:
            zero[j-1]=1
        array.append(zero)
    for i in array:
        print(*i)

if __name__ == "__main__":
    main()

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

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

for i in range(n):

	B = input().split()

	if B[1]!=0:
		for j in range(int(B[1])):
			
			A[i][int(B[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")

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

Solution (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):
        if j!=n-1:
            print(G[i][j],end=" ")
        else:
            print(G[i][j],end="\n")

Solution (Python):
n=int(input())
a=[[0 for i in range(n)]for j in range(n)]
for i in range(n):
    v=list(input().split())
    for j in range(len(v)):
        v[j]=int(v[j])
    x=2
    for k in range(v[1]):
        a[i][v[x+k]-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])

Solution (Python):


n=int(input())

ls=[[0 for i in range(n)]for j in range(n)]
for i in range(n):
	tmp=input().split()
	for j in range(int(tmp[1])):
		
		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]))

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

b=[[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(a[1]):
        b[i][a[2+j]-1]=1
    
for i in range(N):
    print(*b[i])

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


for i in arr:
    print(' '.join(map(str, i)))

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

Solution (Python):
def print_list(a):
    for x in a[:-1]:
        print(x, end=" ")
    print(a[-1])


def print_mat(a):
    for i in range(len(a)):
        print_list(a[i])


n = int(input())
adj = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(n):
    s = [int(x) for x in input().split()]
    u = s[0]
    for v in s[2:]:
        adj[u - 1][v - 1] = 1


print_mat(adj)

Solution (Python):

n=int(input())
list1=[[0 for i in range(n)] for j in range(n)]


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

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

a=[[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:]:
            a[i][j]=1
"""for i in range(n):
    for j in range(n):
        print(a[i][j],"",end="")
    print("")
"""
for i in range(n):
    print(*a[i])

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

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


n = int(input())
mtrx = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
    data = list(input().split())
    adjs = int(data[1])
    for adj in range(adjs):
        j = int(data[adj+2]) - 1
        mtrx[i][j] = 1
for col in mtrx:
    print(" ".join([str(num) for num in col]))

Solution (Python):
import sys

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

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

Solution (Python):


import time
import sys
import io
import re
import math
start = time.clock()
i = 0
n=int(raw_input())
l=[[0 for jc in range(n)] for _ in range(n)]
for a in range(n):
    jk=map(int, raw_input().split())
    for x in range(jk[1]):
        l[jk[0]-1][jk[x+2]-1]=1
 
for i in l:
    print ' '.join(map(str, i))

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
G = {i: [] for i in range(1, n+1)}
for _ in range(n):
    tmp = list(map(int, input().split()))
    G[tmp[0]] += tmp[2:] if tmp[1]>0 else []

adj = [[0]*(1+n) for _ in range(1+n)]
for i in range(1, n+1):
    for j in G[i]:
        adj[i][j] = 1
for i in range(1, n+1):
    print(*adj[i][1:])

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

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

for i in range(n):
    data = [int(i) for i in input().split()]
    for j in range(data[1]):
        node = data[2 + j] - 1
        graph[i][node] = 1

for line in graph:
    print(" ".join(str(i) for i in line))

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

Solution (Python):
import sys
input = sys.stdin.readline

def getNeighbor(A, i):
    a = len(A)
    for k in range(2, a):
        C[i][A[k]-1] = 1

N = int(input())
C = [[0]*N for _ in range(N)]
for i in range(N):
    A = list(map(int, input().split()))
    getNeighbor(A,i)
for i in range(N):
    print(*C[i])

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

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

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

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

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array





sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    for _ in range(N):
        v, k, *U = il()
        for u in U:
            G[v - 1][u - 1] += 1

    for g in G:
        print(*g)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
Adj = [list(map(int, input().split())) for _ in range(n)]

m = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
    if Adj[i][1]>0:
        for a in Adj[i][2:]:
            m[i][a-1] = 1
for e in m:
    print(*e)

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

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

for i in range(n):
    row = [ int(r) for r in input().split()]
    u = row[0] - 1
    if (row[1] > 0):
        for j in range(row[1]):
            v = row[2 + j] - 1
            A[u][v] = 1
            
for i in range(n):
    print(" ".join([str(st) for st in A[i]]))

Solution (Python):



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

Solution (Python):
n = int(input())
Adj = []
for i in range(n):
    X = list(map(int, input().split()))[2:]
    for j in range(len(X)):
        X[j] -= 1
    Adj.append(X)
    
A = [[0]*n for _ in range(n)]
for i in range(n):
    for j in Adj[i]:
        A[i][j] = 1
for i in range(n):
    print(*A[i])

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

for i in range(N):
    
    tmp = input().split()
    ans = [0]*N
    
    for j in range(int(tmp[1])):
        ans[int(tmp[2+j])-1] = 1

    print(*ans)

Solution (Python):


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

for i in range(n):
    cmd = input().split();
    m = int(cmd[1])
    for j in range(m):
        mat[i][int(cmd[2+j])-1] = 1

for i in mat:
    print(*i)

Solution (Python):
n=int(input())
adj=[list(map(int,input().split())) for _ in range(n)]

lst=[[0 for i in range(n)] for j in range(n)]
for x in adj:
    u,v=x[0],x[2:]
    for y in v:
        lst[u-1][y-1]=1

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

Solution (Python):
N = int(input())
G = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
    u,k,*varray = map(int,input().split())
    for v in varray:
        G[u-1][v-1] = 1
    
    
for row in G:
    print(*row)

Solution (Python):
n = int(input())
l = []
tmp = 0 
for _ in range(n):
    a = list(map(int,input().split()))
    l.append(a)
    if a[len(a)-1] > tmp:
        tmp = a[len(a)-1]

ans = [[0 for i in range(tmp)] for j in range(n)]
for i in range(n):
    if l[i][1] > 0:
        for j in range(2,len(l[i])):
            tmp1 = l[i][j]
            ans[i][tmp1-1] = 1

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

Solution (Python):
n=int(input())
graph={}

def show(nums):
    for i in range(len(nums)):
        if i!=0:
            if i!=len(nums)-1:
                print(nums[i],end=" ")
            else:
                print(nums[i])

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

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

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

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

    u, k = s.pop(), s.pop()
    se = set()
    for j in range(k):
        se.add(s.pop())

    ans = []
    for i in range(1, n + 1):
        ans.append(int(i in se))

    print(*ans)

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

for i in range(n):
    ans = [0] * n
    tmp = list(map(int, input().split()))
    u, k, v = tmp[0], tmp[1], tmp[2:]
    for j in v:
        ans[j-1] = 1
    print(' '.join(map(str, ans)))

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

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

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

Solution (Python):
n = int(input())
for i in range(n):
    a = list(map(int,input().strip().split()))
    b = [str(int(i+1 in a[2:])) for i in range(n)]
    L=' '.join(b)
    print(L)

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

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

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

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

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

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

for i in range(N):
    T=list(map(int,input().split()))
    if T[1]!=0:
        
        for j in range(T[1]):
            S[i][T[j+2]-1]=1

for i in S:
    print(*i)

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

a = [[0]*n for x in range(n)]

for i in range(n):
  nood = list(map(int,input().split()))
  nood_elements = nood[0]-1
  for j in range(2,len(nood)):
    a[nood_elements][nood[j]-1] += 1
  
  for j in range(n-1):
    print(a[nood_elements][j],end=" ")
  print(a[nood_elements][n-1])

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

Solution (Python):
import sys, collections
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()
    Adj = [[0]*n for _ in range(n)]
    for _ in range(n):
        ukv = LI()
        u = ukv[0]
        
        v = ukv[2:]
        for i in v:
            Adj[u-1][i-1] = 1

    for i in Adj:
        print(*i)

if __name__ == '__main__':
    resolve()

Solution (Python):
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]
l1 = list( [0 for i in range(n)] for _ in range(n))
for i in l:
  a,b,*c = i
  for j in c:
    l1[a-1][j-1] = 1
for k in l1:
  print(*k)

Solution (Python):
import sys

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

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

for g in G:
    print(*g)

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

Solution (Python):
n=int(input())
L=[]
for l in range(n):
    L.append([])
M=[]
for m in range(n):
    mm=[0]*n
    M.append(mm)

for i in range(n):
    inp=list(map(int,input().split()))
    
    L[inp[0]-1]=inp[2:]

for i,l in enumerate(L):
    for k in l:
        M[i][k-1]=1

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

Solution (Python):
n = int(input())
ls = [[] for i in range(n)]
for i in range(n):
    s = list(map(int,input().split()))
    for j in range(s[1]):
        ls[i].append(s[j+2])
ls2 = [[0 for i in range(n)] for i in range(n)]
for i in range(len(ls)):
    for j in range(len(ls[i])):
        ls2[i][ls[i][j]-1] += 1
    print(*ls2[i])

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

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

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

out_list = [[0 for i in range(n)] for l in range(n)]

for a,in_lst in enumerate(lst):
    for x in range(in_lst[1]):
        out_list[a][in_lst[x+2]-1] = 1


for o1 in out_list:
    print(' '.join([str(x) for x in o1]))

Solution (Python):
n = int(input())
G = [[0]*n for i in range(n)]
for i in range(n):
  u,k,*vs = map(int,input().split())
  for j in range(len(vs)):
    G[u-1][vs[j]-1] = 1 
  
for i in range(n):
  print(" ".join(map(str,G[i])))

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

for i in range(n):
    tmp=list(map(int,input().split())) 
    
    for j in tmp[2:]:
        m[i][j-1]=1
    
    
for i in range(n):
    print(" ".join(list(map(str,m[i]))))

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

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

    result = [0]*n
    count = u[1]

    for j in range(count):
        result[u[j+2]-1] = 1

    print(*result)

Solution (Python):
N=int(input())
matrix=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
    a,b,*c=input().split()
    a=int(a)
    for k in c:

        matrix[a-1][int(k)-1]=1
for i in range(len(matrix)):
    print(*matrix[i])

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

M=[[0]*N for n in range(N)]
for n in range(N):
    input_temp = list(map(int,input().split()))
    for m in range(input_temp[1]):
        ad = input_temp[m+2]
        M[n][ad-1] = 1 
        
for m in M:
    print(' '.join(map(str,m)))

Solution (Python):
n = int(input())
Adj = [[] for _ in range(n+1)]
C = [[0]*(n+1) for _ in range(n+1)]

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

for i in range(n):
    print(*C[i+1][1:])

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

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

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

for _ in range(n):
    u, k, *V = map(int, input().split())
    if k == 0:
        continue
    for j in V:
        graph[u-1][j-1] = 1

for g in graph:
    print(' '.join(map(str, g)))

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

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

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

for i in graph:
    print(*i)

Solution (Python):


n = int(input())
A = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    dat = [int(i) for i in input().split()]
    for v in dat[2:]:
        A[dat[0]-1][v-1] = 1

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

Solution (Python):
import sys
input=sys.stdin.buffer.readline
N = int(input())
M = [[0]*N for _ in range(N)]
for _ in range(N):
    nums = list(map(int,input().split()))
    a = nums[1]
    if a == 0:
        continue
    else:
        for j in nums[2:]:
            M[nums[0]-1][j-1] = 1
for i in range(N):
    print(" ".join(map(str,M[i])))

Solution (Python):
n = int(input())
L = [[] for _ in range(n)]
for i in range(n):
    L[i] = [i for i in map(int,input().split())]
    L[i].remove(L[i][0])
    if L[i] != []:
        L[i].remove(L[i][0])
for i in range(n):
    adjacent = [0 for _ in range(n)]
    for el in L[i]:
        adjacent[el-1] = 1
    print(' '.join(map(str,adjacent)))

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

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

	for i in range(n):
		cmd = input().split();
		m = int(cmd[1])
		for j in range(m):
			A[i][int(cmd[2+j])-1] = 1

	for i in A:
		print(*i)

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

    adjacency_matrix = []
    for _ in range(n):
        u, k, *V = map(int, input().split())
        col = [0] * n
        for v in V:
            col[v-1] = 1
        adjacency_matrix.append(col)
    for col in adjacency_matrix:
        print(*col)


if __name__ == "__main__":
    main()

Solution (Python):
def Main():
    N = int(input())
    adj = [[0]*N for i in range(N)]

    for n in range(N):
        u, k, *V = map(int, input().split())
        
        if k > 0:
           for i in V:
            adj[u - 1][i - 1] = 1

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

Main()

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

Solution (Python):

import sys
input = sys.stdin.readline
n = int(input())
A = [tuple(map(int, input().split())) for _ in range(n)]

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

for i, k, *V in A:
    for v in V:
        G[i-1][v-1] = 1

for g in G:
    print(*g)