Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		arr[u-1] = make([]int, n)
		for j := 0; j < k; j++ {
			n := scanInt()
			arr[u-1][n-1] = 1
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for _, col := range arr {
		fmt.Fprintln(w, strings.Trim(fmt.Sprint(col), "[]"))
	}
	w.Flush()
}

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;
}

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

int main() {
	int n, u, k, x;
	int matrix[101][101] = {};

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> x;
			matrix[u][x] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cout << matrix[i][j] << " " ;
		}
		cout << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int g[101][101];
int main(void){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v;
      cin>>v;
      g[u][v]=1;
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      cout<<g[i][j]<<" \n"[j==n];
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
static const int MAX  = 100;
int main ()
{
  int n,u,k,v;
  cin>>n;
  int M[MAX][MAX];
  for(int i  = 0;i<n;i++)
    {
      for(int j = 0;j<n;j++)
        {
          M[i][j] = 0;
        }
    } 
  for(int i = 0;i<n;i++)
   {
     cin>>u>>k;
     u--;
     for(int j = 0;j<k;j++)
       {
         cin>>v;
         v--;
         M[u][v] = 1;
       }
   } 
   for(int i = 0;i<n;i++)
     {
       for(int j = 0;j<n;j++)
        { if(j) cout<<" ";
         else cout<<M[i][j];
     }
     cout<<endl;
   }
  return 0 ;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define N_MAX 100

int main() {
    long n, v, deg_out, e;
    cin >> n;

    long G[N_MAX][N_MAX] = {};

    for (long i = 0; i < n; i++) {
        cin >> v >> deg_out;
        for (long j = 0; j < deg_out; j++) {
            cin >> e;
            G[v - 1][e - 1] = 1;
        }
    }

    for (long i = 0; i < n; i++) {
        for (long j = 0; j < n; j++) {
            if (j != 0) { cout << " "; }
            cout << G[i][j];
        }
        cout << endl;
    }

    return 0;
}

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

int main() {
	int a[100][100];
	int n;
	cin >> n;
	int u, k, v;
	for ( int i = 0; i < n; i++ ) {
		for ( int x = 0; x < 100; x++ )
			for ( int y = 0; y < 100; y++ )
				a[x][y] = 0;
		cin >> u >> k;
		for ( int j = 0; j < k; j++ ) {
			cin >> v;
			a[u][v] = 1;
		}
	}
	for ( int i = 0; i < n; i++ ) {
		for ( int j = 0; j < n; j++ )
			cout << a[i][j] << " ";
		cout << endl;
	}
}