Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

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



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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    graph = [[0 for i in range(n)] for _ in range(n)]
    for i in range(n):
        datas = [int(num) for num in input().split(' ')]
        if datas[1] > 0:
            for j in datas[2:]:
                graph[datas[0] - 1][j - 1] = 1

    for row in graph:
        print(str(row).replace(',', '').replace('[', '').replace(']', ''))

Submission status: Accepted

Solution code:
num = int(input())

mat = [[0 for i in range(num)] for j in range(num)]

for i in range(num):
    arr = list(map(int,input().split()))
    
    if  arr[1] >= 1:
        for j in range(len(arr)-2):
            m = arr[j+2]
            
            mat[i][m-1] += 1

    else:
        pass

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

Submission status: Accepted

Solution code:

n=int(input())
A=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
    point=[int(j) for j in input().split()]
    if point[1]>0:
        for k in point[2:]:
            if k:A[i][k-1]=1
                
for i in A:
    print(*i)

Submission status: Accepted

Solution code:

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

for i in range(n):
    _ = list(map(int, input().split()))
    u = _[0] - 1  # 0オリジンに変換

    degree = _[1]
    for j in range(degree):
        v = _[j+2] - 1  # 0オリジンに変換
        M[u][v] = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
answerL = []
for i in range(n):
    inputL = input().split()
    newL = [0]*n
    k = int(inputL[1])
    for j in range(k):
        target = int(inputL[1+j+1])
        newL[target-1] = 1
    answerL.append(newL)
for ans in answerL:
    print(' '.join(list(map(str, ans))))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    
    graph = [[0 for _ in range(n)] for _ in range(n)]

    for _ in range(n):
        u, k, *v_s = map(int, input().split(' '))
        for j in range(k):
            graph[u-1][v_s[j-1]-1] = 1
    
    for row in graph:
        print(' '.join(map(str, row)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

n=int(input())
G=[[0]*n for i in range(n)]
for i in range(n):
    inp=tuple(map(int,input().split()))
    now=inp[0]
    for j in range(2,inp[1]+2):
        G[now-1][inp[j]-1]=1
for g in G:
    print(*g)

Submission status: Accepted

Solution code:
# 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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

dic = {}
for _ in range(n):
    datum = list(map(int, input().split()))
    status = ["0"]*n
    for i in datum[2:]:
        status[i-1] = "1"
    print(" ".join(status))

Submission status: Accepted

Solution code:
#ALDS1_11_A Graph
import sys

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

for i in range(n):
    Adj = list(map(int, sys.stdin.readline().strip().split()))
    if Adj[1] >= 1:
        v = Adj[2:]
        for j in v:
            A[i][j - 1] = 1
            # A[j - 1][i - 1] = 1

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

Submission status: Accepted

Solution code:
N = int(input())
L = [list(map(int, input().split())) for i in range(N)]
adj = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
  for node in L[i][2:]:
    adj[i][node-1] = 1

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

Submission status: Accepted

Solution code:
num = int(input())
L = [[ 0 for x in range(num)] for y in range(num)]
for _ in range(num):
    c,k,*v = [int(x)-1 for x in input().split()]
    for i in v:
        L[c][i] = 1
for i in range(num):
    print( *L[i] )

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    G = [[0] * n for _ in range(n)]
    for i in range(n):
        u, k, *v = map(int, input().split())
        for j in range(k):
            G[u-1][v[j]-1] = 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    m = [[0] * n for _ in range(n)]
    for _ in range(n):
        u, k, *v = map(int, input().split())
        for i in range(k):
            m[u - 1][v[i] - 1] = 1
    for row in m:
        print(' '.join(map(str, row)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)

n=int(stdin.readline().rstrip())
ans=[[0]*n for _ in range(n)]
for i in range(n):
    v=list(map(int,stdin.readline().rstrip().split()))
    for j in v[2:]:
        ans[v[0]-1][j-1]=1
for i in ans:
    print(*i)

Submission status: Accepted

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

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

    for j in range(2,len(u)):
        G[i][u[j]-1]=1


G=[' '.join(map(str,G[i])) for i in range(n)]
print('\n'.join(G))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    num_vertices = int(input())
    adj_matrix = [[0] * num_vertices for i in range(num_vertices)]

    for _ in range(num_vertices):
        vertex, _, *adjs = map(lambda x: int(x), input().split())
        for adj in adjs:
            adj_matrix[vertex -1][adj - 1] = 1

    for row in adj_matrix:
        print(" ".join([str(elem) for elem in row]))

Submission status: Accepted

Solution code:
n=int(input())
a=[[0]*n for _ in range(n)]
u=0
k=0
for i in range(n):
    ukv=list(map(int,input().split()))
    for j in range(2,2+ukv[1]):
        a[ukv[0]-1][ukv[j]-1]=1
for i in range(n):
    print(" ".join(map(str,a[i])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
V=[]
for i in range(n):
    temp=input().split( )
    l=len(temp)
    v=[]
    for j in range(l):
        v.append(int(temp[j]))
    V.append(v)
A=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
    k=V[i][1]
    if k>0:
        for j in range(k):
            A[V[i][0]-1][V[i][j+2]-1]=1
for i in range(n):
    print(*A[i])

Submission status: Accepted

Solution code:
n = int(input())
l = []
pad = 0
for i in range(n):
    m = [0]*n
    s = list(map(int,input().split()))
    if s[1] != 0:
        for j in s[2:]:
            m[j-1] = 1
    
    print(*m)

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

for i in range(n):

    u, k, *V = map(int, input().split())

    for v in V:
        v -= 1
        matrix[i][v] = 1


for row in matrix:
    print(*row)

Submission status: Accepted

Solution code:
N = int(input())
G = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    ls = list(map(int,input().split()))
    u = ls[0] - 1
    for v in ls[2:]:
        G[u][v-1] = 1

for row in G:
    print(' '.join(map(str,row)))

Submission status: Accepted

Solution code:
N = int(input())
P = [[0 for _ in range(N)] for _ in range(N)] 
for i in range(N):
    u,k,*varray = map(int,input().split()) # u,k は数, varray は配列
    for v in varray:
        P[u-1][v-1] = 1
for j in P:
    print(" ".join(map(str,j)))

Submission status: Accepted

Solution code:
n = int(input())
matrix = [[0] * n for _ in range(n)]
for _ in range(n):
    line = list(map(int, input().split()))
    u = line[0]
    for v in line[2:]:
        matrix[u-1][v-1] = 1
for row in matrix:
    print(' '.join(map(str, row)))

Submission status: Accepted

Solution code:
n = int(input())
G = []
for i in range(n):
    T = [0]*n
    G.append(T)
for i in range(n):
    L = list(map(int,input().split()))
    for j in range(2,len(L)):
        G[i][L[j]-1] += 1
for i in range(n):
  print(' '.join(map(str,G[i])))

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
  l1=list(map(int,input().split()))
  l2=[]
  if l1[1]==0:
    l2=["0" for j in range(n)]
  else:
    for j in range(n):
      if j+1 in l1[2:]:
        l2.append("1")
      else:
        l2.append("0")
  print(" ".join(l2))

Submission status: Accepted

Solution code:
n = int(input())
matrix = [[0]*n for i in range(n)]
for _ in range(n):
    lis = list(map(int,input().split()))
    if lis[1] > 0:
        for i in lis[2:]:
            matrix[lis[0]-1][i-1] = 1

for lis in matrix:
    x = list(map(str,lis))
    print(" ".join(x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=[[0]*n for _ in range(n)]
for _ in range(n):
    u,k,*v=map(int,input().split())
    for j in v:
        a[u-1][j-1]=1
for row in a:
    print(*row)

Submission status: Accepted

Solution code:
n = int(input())

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

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

for ret in results:
    for i in range(len(ret)):
        if i == len(ret)-1:
            print(ret[i], end='')
        else:
            print(ret[i], '', end='')
    print('')

Submission status: Accepted

Solution code:
n=int(input())
matrix=[]
for i in range(n):
    matrix.append([0]*n)
for i in range(n):
    listi=list(map(int,input().split()))
    for j in range(listi[1]):
        matrix[i][listi[j+2]-1]=1

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

Submission status: Accepted

Solution code:
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=' ')

Submission status: Accepted

Solution code:

N = int(input())
T = [[0] * (N+1) for _ in range(N+1)]
for i in range(N):
    tmp = [int(ele) for ele in input().split()]
    from_ = tmp[0]
    for j in tmp[2:]:
        T[from_][j] = 1


def main():
    for i in T[1:]:
        ans = ""
        for j in i[1:]:
            ans += str(j) + " "
        print(ans[:-1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
n = int(input())
adj_list = [[0]*n for _ in range(n)]
for _ in range(n):
    input_list = list(map(int, input().split()))
    u = input_list[0] - 1
    e_num = input_list[1]
    if e_num > 0:
        for i in range(e_num):
            adj_list[u][input_list[i+2] - 1] = 1

for adj in adj_list:
    print(' '.join(map(str, adj)))

Submission status: Accepted

Solution code:
n = int(input()) #頂点数

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

for i in range(n):
    adj_list = list(map(int,input().split()))
    for j in adj_list[2:]: #3番目からの隣接ノードを取得する
        matrix[i][j-1] = 1 #隣接ノードを成分を1に変更する

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

Submission status: Accepted

Solution code:
n = int(input())
adj = [[0]*n for i in range(n)]
for i in range(n):
    a, *b = input().split()[1:]
    for j in b:
        adj[i][int(j)-1] = 1
for i in range(n):
    print(*adj[i])

Submission status: Accepted

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

Submission status: Accepted

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

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

    for j in inta[2:2+inta[1]]:
        ans[inta[0]-1][j-1] = 1

for i in ans:
    print(" ".join(map(str,i)))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    u, k, *v, = map(int, input().split())
    r = []
    for j in range(1, n+1):
        r.append(str(1 if j in v else 0))
    print(" ".join(r))

Submission status: Accepted

Solution code:
n = int(input())
adj = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
    l = list(map(int, input().split()))
    if l[1] == 0:
        print(' '.join(list(map(str, adj[i]))))
        # continue
    else:
        for j in range(2,len(l)):
            adj[l[0]-1][l[j]-1] = 1
        print(' '.join(list(map(str, adj[i]))))
# for i in range(n):
    # print(' '.join(list(map(str, adj[i]))))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 22 16:34:05 2019

@author: Yamazaki Kenichi
"""

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

T = [[0 for i in range(n)] for i in range(n)]

for c in A:
    if c[1] != 0:
        for i in range(c[1]):
            T[c[0]-1][c[i+2]-1] = 1

for c in T:
    print(' '.join(map(str,c)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input().rstrip())
A = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N):
    line = [int(i) for i in input().rstrip().split()]
    for j in range(line[1]):
        A[line[0]-1][line[j+2]-1] = 1

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

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = [[0]*(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)):
        L[D[0]][D[j]] = 1
for i in range(1,N+1):
    print(' '.join(map(str,L[i][1:])))

Submission status: Accepted

Solution code:
#-*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A
"""
import itertools


def input_from_txt(number=1):
    import requests
    #url = "https://judgedat.u-aizu.ac.jp/testcases/ALDS1_4_A/8/in"
    url = "https://judgedat.u-aizu.ac.jp/testcases/ALDS1_11_A/%s/in" % number
    res = requests.get(url)
    input = res.text.split("\n")
    n = int(input[0])
    Ss = []
    for i in range(n):
        S = list(map(int, input[1+i].split()))
        Ss.append(S)
    return (n, Ss)

def input_array():
    n = int(input())
    Ss = []
    for i in range(n):
        S = list(map(int, input().split()))
        Ss.append(S)
    return (n, Ss)


if __name__ == '__main__':
    (n, Ss) = input_array()
    #(n, Ss) = input_from_txt(1)
    #print(n, Ss)
    for i in range(n):
        vth = Ss[i][0]
        vd = Ss[i][1]
        adjs = Ss[i][2:]
        row = []
        for j in range(1, 1+n):
            if j in adjs: row.append(1)
            else: row.append(0)
        print(" ".join(map(str, row)))
    #ret = get_set4(S, T)
    #ret = get_set2(S, T)
    #ret = get_set(S, T)
    #print(len(ret))

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A&lang=jp
# Graph: python3
#  2018.12.04 yonezawa

import sys
input = sys.stdin.readline
#import cProfile
def main():
    n = int(input())
    nmap = [[0 for i in range(n)] for i in range(n)]

    for _ in range(n):
        l = list(map(int,input().split()))
        a = l[0] - 1
        for i in l[2:]:
            nmap[a][i-1] = 1
    for i in nmap:
        print (*i)
        
if __name__ == '__main__':
    main()
    #pr = cProfile.Profile()
    #pr.runcall(main)
    #pr.print_stats()

Submission status: Accepted

Solution code:
import collections
N = int(input().strip())
Adj = []
for u in range(N):
    Adju = [0 for _ in range(N)]
    Adjlst = collections.deque(list(map(int,input().strip().split(" "))))
    Adjlst.popleft()
    K = Adjlst.popleft()
    for k in range(K):
        v = Adjlst.popleft()
        Adju[v-1] = 1
    Adj.append(Adju)
for i in range(N):
    for j in range(N-1):
        print(Adj[i][j],"",end="")
    print(Adj[i][N-1])

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline())

for i in range(n):
    aa = list(map(int, sys.stdin.readline().split()))
    c = [0] * n
    for j in aa[2:]:
        c[j-1]=1
    print(' '.join(map(str,c)))

Submission status: Accepted

Solution code:
import sys

N = int(input())
matrix = [[0]*N for _ in [0]*N]
for u, k, *v_a in (map(int, l.split()) for l in sys.stdin):
    for v in v_a:
        matrix[u-1][v-1] = 1

print(*(" ".join(map(str, row)) for row in matrix), sep="\n")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input())
for i in range(N):
    u, k, *vs = map(int, input().split())
    E = [0]*N
    for v in vs:
        E[v-1] = 1
    print(*E)

Submission status: Accepted

Solution code:
n = int(input())
list_m = [[0] * n for i in range(n)]
for i in range(n):
	a,b, *args = map(int,input().split())
	for num in args:
		list_m[a-1][num-1] = 1
for i in range(n):
	for j in range(n):
		list_m[i][j] = str(list_m[i][j])
for row in list_m:
	print(" ".join(row))

Submission status: Accepted

Solution code:
def read_adj_list(n):
    al = [None for _ in range(n + 1)]
    for _ in range(n):
        u, _, *v = (int(x) for x in input().split())
        al[u] = v
    return al


def adj_list_to_matrix(n, al):
    am = [[0] * (n + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in al[i]:
            am[i][j] = 1
    return am


def print_adj_mat(n, am):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            if j > 1:
                print(" ", end="")
            print(am[i][j], end="")
        print()


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

    adj_list = read_adj_list(n)
    adj_mat = adj_list_to_matrix(n, adj_list)
    print_adj_mat(n, adj_mat)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


V = int(input())

table = [['0']*V for i in range(V)]

for loop in range(V):
    tmp_array = list(map(int,input().split()))
    node_id = tmp_array[0]-1
    for i in range(tmp_array[1]):
        table[node_id][tmp_array[2+i]-1] = '1'

for row in range(V):
    print(' '.join(table[row]))

Submission status: Accepted

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

for i in range(n):
	print(a[i][0],end='')
	for j in range(1, n):
		print(' ' + str(a[i][j]),end='')
	print()

Submission status: Accepted

Solution code:
n = int(input())

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

for i in range(n):
    [*s] = map(int, input().split(' '))
    for k in range(s[1]):
        g[i][s[2 + k] - 1] = 1

for i in range(n):
    for j in range(n):
        if j != 0:
            print(' ', end='')
        print(g[i][j], end='')
    print()

Submission status: Accepted

Solution code:
n = int(input())
m = [[0] * n for i in range(n)]
for i in range(n):
    line = [int(v) for v in input().split()]
    u = line[0] - 1
    for v in line[2:]:
        v -= 1
        m[u][v] = 1

for row in m:
    print(' '.join([str(v) for v in row]))

Submission status: Accepted

Solution code:
n = int(input())
rlist = [[]]
alist = [[]]
for i in range (n):
    alist.append(input().split())
    rlist.append([0]*n)
alist.pop(0)
rlist.pop(0)
for i in range(n):
    for j in range(2,len(alist[i])):
        rlist[i][int(alist[i][j])-1] = 1
    print(*rlist[i])

Submission status: Accepted

Solution code:
# coding: utf-8

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

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

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


# 入力: 隣接リストを与える
# 出力: 隣接行列を出力する

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Graph I - Graph
n = int(input())
for _ in range(n):
    ss = list(map(int, input().split()))
    u = ss[0] - 1
    row = [0 for _ in range(n)]
    for i in range(ss[1]):
        idx = 2 + i
        row[ss[idx]-1] = 1
    print(*row)

Submission status: Accepted

Solution code:
n=int(input())
G=[[0 for i in range(n+1)] for i in range(n+1)]
for i in range(n):
    arr=[int(x) for x in input().split()[2:]]
    for j in arr:
        
        G[i+1][j]=1
        
for k in range(1,n+1):
    G[k].pop(0)
    print(' '.join(map(str, G[k])))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
result = np.array([[0]*4]*4)
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])

Submission status: Runtime Error

Solution code:
# 入力
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]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(n):
  for j in range(n):
    print(v[i][j]+" ")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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 node in range(n):
    out = ''
    for adj in range(n):
        if adj + 1 != n:
            out += '1 ' if adj + 1 in G.nodes[node] else '0 '
        else:
            out += '1' if adj + 1 in G.nodes[node] else '0'
    print(out)

Submission status: Runtime Error

Solution code:
import sys


class Graph:
    def __init__(self, nodes={}):
        self.nodes = nodes
    def printAdjMatrix(self):
        # assuming that nodes' indices are 1,2,3,...,n
        n = len(self.nodes)
        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)


n = int(input())
G = Graph()
for line in sys.stdin:
    numList = list(map(int, line.split()))
    G.nodes[numList[0]] = list(numList[2:])

G.printAdjMatrix()