Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	g := make([][]int, n)

	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
	}

	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		u--
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			v--
			g[u][v] = 1
		}
		fmt.Fprintln(writer, joinint(g[u], " "))
	}

	writer.Flush()
}

func joinint(a []int, sep string) string {
	n := len(a)
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		ss[i] = fmt.Sprintf("%d", a[i])
	}
	return strings.Join(ss, sep)
}

Python: n = int(input())
adj = []
# adj = [[None] * n for _ in range(n)]
ans = [[0] * n for _ in range(n)]

for i in range(n):
    temp = list(map(int, input().split()))
    if len(temp) > 2:
        adj.append(temp[2:])
    else:
        adj.append([])

# print(adj)
# print(ans)

for i in range(n):
    for j in range(len(adj[i])):
        ans[i][adj[i][j]-1] = 1

# print(ans)

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

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

Python: 
N = int(input())

# initialize
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], end="")

            if i != N-1: print("")

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

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

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

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

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

Python: #16D8101016B IshizakiTatsuya 石崎達也 python3



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

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

Python: # your code goes here
#graph
#????????????????¨?????????¨
n=int(input())
L=[]
for i in range(n):
    L.append([])
    for j in range(n):
        L[i].append("0")
#rint(L)
for i in range(n):
    v=[int(i) for i in input().split()]
#    print(v)
    for j in range(2,2+v[1]):
        L[v[0]-1][v[j]-1]="1"#??????????????????1????????????i???i-1
#        print(L)
     #   L[v[j]-1][v[0]-1]="1"
for i in range(n):
    print(" ".join(L[i]))

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)

Python: # coding=utf-8

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 #for index
    if k == 0:
        continue
    for num in v:
        num = num-1 #for index
        M[u][num] = 1
for row in M:
    print(*row)

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

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

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

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

Python: 
N = int(input())

# initialize
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):
        print(ans[i][j], end=" ")
        if j == N-1: print()

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

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)

Python: import numpy as np
n=int(input())
g=np.zeros((n,n),dtype=np.int)
for i in range(n):
	s=list(map(int,input().split()))
	for j in range(s[1]):
		g[s[0]][s[2+j]]+=1
print(g)