Go: package main

/*
グラフの表現 隣接行列による表現
*/

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

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		ints := eGetInts(scanner)
		num := ints[0]
		for j := 0; j < ints[1]; j++ {
			g[num-1][ints[j+2]-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		s := fmt.Sprint(g[i])
		fmt.Println(s[1 : len(s)-1])
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

Python: n=int(input()) #รับจำนวน node ทั้งหมด
m=[[0]*n for i in range(n)] #สร้าง array matrix 0 ขนาดเท่าจำนวน node

for i in range(n):
    tmp=list(map(int,input().split())) #วน loop ตามจำนวน node รับค่าข้อมูลแต่ละ node
    #ตน 0 คือ node , ตน 1 คือ จำนวน vertex ตน 2 เป็นต้นไปคือ vertex
    for j in tmp[2:]:
        m[i][j-1]=1
    #แสดงผล node และ vertex ที่มีความสัมพันธ์กัน ใส่ 0 เมื่อไม่เกิดความสัมพันธ์ ใส่ 1 เมื่อเกิด
    #Show เป็น Matrix    
for i in range(n):
    print(" ".join(list(map(str,m[i]))))

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

Python: def conv_list(n):
    adj_matrix = []
    for _ in range(n):
        adj_list = input().split()
        adj_list = list(map(int, adj_list))
        adj_row = [0] * n
        if adj_list[1] > 0:
            for i in adj_list[2:]:
                adj_row[i - 1] = 1
        adj_matrix.append(adj_row)
    return adj_matrix


def main():
    n = int(input())
    adj_matrix = conv_list(n)
    for row in adj_matrix:
        print(" ".join(map(str, row)))


if __name__ == "__main__":
    main()

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

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)

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

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

Python: #coding:utf-8
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)

Python: 
n = int(input())

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

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

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

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

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

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

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

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)

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