Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	g := make([][]int, N)
	for i, _ := range g {
		g[i] = make([]int, N)
	}
	for i := 0; i < N; i++ {
		u, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			g[u-1][sc.nextInt()-1] = 1
		}
	}

	for _, r := range g {
		for i, num := range r {
			if i > 0 {
				fmt.Fprint(wtr, " ")
			}
			fmt.Fprint(wtr, num)
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}

Python: # -*- 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)))

Python: # -*- coding: utf-8 -*-

n = int(input())

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

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

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

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

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)

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