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())
for _ in range(n):
    u=list(map(int,input().split()))
    out=[0]*n
    for i in u[2:]: out[i-1] = 1
    print(*out)

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

Python: from sys import stdin

X = [ 0 for i in range(100) ]
G = [[ 0 for i in range(100) ] for i in range(100)]

n = int(input())
for i in range(n) :
	X[i] = stdin.readline().strip().split()


for i in range(n) :
	for j in range(int(X[i][1])) :
		G[i][int(X[i][j+2])-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])

Python: # Graph

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

for i in range(N):
    lst = list(map(int, input().split()))
    idx = lst[0]
    for j in range(lst[1]):
        G[idx-1][lst[2:][j]-1] = 1
    print(*G[idx-1])

Python: n = int(input())

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

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

for a_l in adj_mat:
    print(*a_l[1:])

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

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

Python: l = int(input())
rlist = []
for i in range(l):
    li = list(map(int, input().split()))
    rlist.append(li[2:])

result = []
for i in range(l):
    rcell = [0] * l
    for rl in rlist[i]:
        rcell[rl-1] = 1

    result.append(rcell)

for r in result:
    re = ''
    for rr in r:
        re += str(rr) + ' '

    print(re[:-1])

Python: #16D8102008K Yagyu Hazuki
n=int(input())
dp = [[0 for i in range(n)] for j in range(n)] 

for _ in range(n):
    inputs = list(map(int, input().split()))
    u = inputs[0]
    k = inputs[1]
    v = inputs[2:]
    for each in v:
        dp[u-1][each-1] = 1
for i in range(n):
    for j in range(n):
            print(dp[i][j],end=' ')
    print()

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

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

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

Python: n = int(input())
for _ in range(n):
    u = list(map(int,input().split()))
    out = [0]*n
    for i in range(u[1]): out[u[i+2]-1] = 1
    print(*out)

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

a=[[0 for i2 in range(n)]for i1 in range(n)]

for i in range(n):
    for j in range(adj[i][1]):
        a[i][adj[i][j+2]-1]=1

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

Python: def main():
    num = int(input())
    T = [[0] * num for i in range(num)]
    for n in range(num):
        a = list(map(int,input().split()))
        u = a[0] - 1
        if a[1] > 0:
            for i in a[2:]:
                print(i)
                T[u][i-1] = 1

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

if __name__ == '__main__':
    main()

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys


def generate_graph(v_info):
    for info in v_info:
        adj_info = info[2:]
        for each in adj_info:
            adj_matrix[int(info[0]) - 1][int(each) - 1] = 1
    return adj_matrix


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertex_num = int(_input[0])
    vertex_info = list(map(lambda x: x.split(), _input[1:]))
    adj_matrix = [[0] * vertex_num for _ in range(vertex_num)]
    # assert len(vertex_info) == vertex_num

    ans = generate_graph(vertex_info)
    for v_result in ans:
        print(*v_result)

Python: from sys import stdin
n = int(stdin.readline())
v = [[0] * (n + 1) for i in range(n + 1)]
for u in range(1, n + 1):
    U = [int(j) for j in stdin.readline().split()]
    for k in U[2:]:
        v[u][k] += 1
for i in range(1, n + 1):
    print(*v[i][1:])

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

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

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