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
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> p;

int main(void){
  int n,a,b,c;
  cin >> n;
  int v[n][n];
  for(int i=0;i<n;i++){
    cin >> a >> b;
    for(int j=0;j<b;j++){
      cin >> c;
      v[a-1][c-1]=1;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(v[i][j]!=1)cout << 0;
      else cout << v[i][j];
      if(j!=n-1)cout << ' ';
    }
    cout << endl;
  }
  return 0;
}

C++: # include <iostream>
# include <cstring>
# include <cstdio>
using namespace std;
int main(void)
{
	int a[105][105];
    int n,cnt,u,k;
    memset(a,0,sizeof(a));
    scanf("%d",&n);
    for(int w = 0;w < n;w++)
    {
    	scanf("%d %d",&u,&cnt);
    	for(int i = 0;i < cnt;i++)
    	{
    		scanf("%d",&k);
    		a[u][k] = 1;
		}
	}
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++) cout<<a[i][j]<<(j == n?"\n":" ");
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<vector<int> > G(n, vector<int>(n, 0));

    for (int y = 0; y < n; y++) {
        int num, k;
        cin >> num >> k;
        for (int i = 0; i < k; i++) {
            int x;
            cin >> x;
            x--;
            G[x][y] = 1;
        }
    }

    for (int y = 0; y < n; y++) {
        cout << G[0][y];
        for (int x = 1; x < n; x++) {
            cout << " " << G[x][y];
        }
        cout << endl;
    }

    return 0;
}

C++: /* ALDS1_11_A: Graph */

#include <iostream>

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n;

    int adjm[n + 1][n + 1];
    for (int row = 1; row <= n; row++)
        std::fill_n(adjm[row], n + 1, 0);

    int u, v, n_degrees;
    for (int i = 0; i < n; i++) {
        std::cin >> u >> n_degrees;
        for (int j = 0; j < n_degrees; j++) {
            std::cin >> v;
            adjm[u][v] = 1;
        }
    }

    for (int row = 1; row <= n; row++) {
        std::cout << adjm[row][1];
        for (int col = 2; col <= n; col++) {
            std::cout << " " << adjm[row][col];
        }
        std::cout << "\n";
    }


    return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;

bool mat[105][105];
int n;
void print(bool x){
    if(x) cout<<"1 ";
    else cout<<"0 ";
}
int main(){
    cin>>n;
    int t=n;
    memset(mat,false,sizeof(mat));
    while(t--){
        int id,k;
        cin>>id>>k;
        while(k--){
            int out;
            cin>>out;
            mat[id][out]=true;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            print(mat[i][j]);
        }
        cout<<endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;

int main(){
    int n;
    cin >> n;
    int Adj[n][n];
    int A[n][n];
    int g1, g2;

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            Adj[i][j] = 0;
            A[i][j] = 0;
        }
    }

    for(int i=0;i<n;i++){
        cin >> g1 >> g2;
        for(int j=0;j<g2;j++){
            cin >> Adj[i][j];
            A[i][Adj[i][j]-1] = 1;
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j==n-1){
                cout << A[i][j];
            } else {
                cout << A[i][j] <<" ";
            }   
        }
        cout << endl;
    }
}

C++: /*
** 邻接表和邻接矩阵来保存图
*/

# include <cstdio>
# include <cstring>

const int MAX = 100 + 2;

int m[MAX][MAX];

int n;

void solve() {
    scanf("%d", &n);
    memset(m, 0, sizeof(m));
    int u, k, v;
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &u, &k);
        while (k-- > 0) {
            scanf("%d", &v);
            m[u-1][v-1] = 1;
        }
    }
        

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j) {
                printf(" ");
            }
            printf("%d", m[i][j]);
        }
        printf("\n");
    }
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}

C++: #include<iostream>
using namespace std;

int main() {
	int n, u, v, l;
	cin >> n;
	int A[n + 1][n + 1];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			A[i][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++) {
		cin >> u >> l;
		for (int j = 0; j < l; j++) {
			cin >> v;
			A[u][v] = 1;
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (j != 1) cout << ' ';
			cout << A[i][j];
		}
		cout << endl;
	}

	return 0;
}

C++: //
// Created by tattsun on 2017/02/11.
//

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;

    int u, k, p;
    for(int i=0; i<n; i++) {
        cin >> u >> k;

        vector<int> dest;
        for(int j=0; j<k; j++) {
            cin >> p;
            dest.push_back(p);
        }

        vector<int>::iterator it = dest.begin();
        for(int j=0; j<n; j++) {
            if(j != 0) cout << " ";
            if(it != dest.end() && j == *it-1) {
                cout << "1";
                it++;
            } else {
                cout << "0";
            }
        }
        cout << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

//??\???????????????
//4
//1 2 2 4
//2 1 4
//3 0
//4 1 3

bool Path[101][101] = {false};

int main(){
    int  N;
    cin >> N;
    int bb;
    for (int i = 1; i <= N; i++) {
        int K;
        scanf("%d %d",&bb,&K);
        for (int k = 0; k < K; k++) {
            int p;
            scanf("%d",&p);
            
            Path[i][p] = true;
        }
    }
    
    for (int r = 1; r <= N; r++) {
        for (int c = 1; c <= N; c++) {
            printf("%d ",Path[r][c]);
        }
        printf("\n");
    }
    return 0;
}