Go: package main

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

const N = 100

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var M [N][N]int
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			M[u][v] = 1
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if j != 0 {
				out.WriteString(" ")
			}
			out.WriteString(fmt.Sprintf("%d", M[i][j]))
		}
		out.WriteString("\n")
	}

	return strings.TrimRight(out.String(), "\n")
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: /* 
 * ALDS1_11.cpp
 * ??£??\???????????¨?????§???????????????????????°??????G?????£??\????????¨?????????????????????????????????
 */
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

using Adjacents = vector<int>;
using Vertexes = vector<Adjacents>;

int main(void) {

    int N;
    scanf("%d", &N);

    Vertexes vs;
    vs.resize(N);
    for (int i = 0, id, num; i < N; ++i) {
        scanf("%d %d", &id, &num);
        for (int j = 0, vert; j < num; ++j) {
            scanf("%d", &vert);
            vs[id-1].push_back(vert);
        }
    }

    int **matrix = new int*[N];
    for (int i = 0; i < N; ++i) {
        matrix[i] = new int[N];
        memset(matrix[i], 0, sizeof(int)*N);
        for (int j = 0; j < vs[i].size(); ++j) {
            matrix[i][vs[i][j] - 1] = 1;
        }
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            //printf("%2d", matrix[i][j]);
            putchar(matrix[i][j] + '0');
            if (j != N - 1)
                putchar(' ');
        }
        delete[] matrix[i];
        printf("\n");
    }
    delete[] matrix;

    return 0;
}

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

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

C++: #include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;

int main() {
	vector<vector<int>> adjM;
	int N;
	cin >> N;
	adjM.resize(N);
	for (int i = 0; i < N; ++i) {
		adjM[i].resize(N);
	}

	for (int i = 0; i < N; ++i) {
		int v, g;
		cin >> v;
		cin >> g;
		for (int j = 0; j < g; ++j) {
			int k;
			cin >> k;
			adjM[v - 1][k - 1] = 1;
		}
	}

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N - 1; ++j) {
			cout << adjM[i][j] << " ";
		}
		cout << adjM[i][N - 1] << endl;
	}

	return 0;
}

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

int main()
{
	int n, A[100][100];
	cin>>n;


	for(int i=0;i<n;++i){

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

		int m,k; //k=number of adj
		cin>>m>>k;
		assert(m==i+1);

		for(int j=0;j<k;++j){
			int adj;
			cin>>adj;
			if(adj){
				A[i][adj-1]=1;
			}
		}
	}

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

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
    
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <limits>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<vector<int>> vec(n);
    vector<int> SIZE;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        int num;
        cin >> num;
        SIZE.push_back(num);
        for(int j = 0;j< num;j++){
            int y;
            cin >> y;
            vec[x-1].push_back(y-1) ;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            bool hantei=0;
            for(int k=0;k<SIZE[i];k++){
                if(vec[i][k]==j) {cout << 1 <<" "; hantei=1;}
            }
            if(hantei==0) cout <<0<<" ";
        }cout << endl;
    }cout << endl;
}

C++: #include <cstdio>
#include <vector>

int main(){
	std::vector< std::vector<int> > M;
	int n, r, k, c;
	scanf("%d", &n);
	M.resize(n);
	for (int i=0;i<n;i++){
		M[i].resize(n);
		scanf("%d %d", &r, &k);
		for (int j=0; j<k;j++){
			scanf("%d", &c);
			M[i][c-1]=1;
		}
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			printf("%d ", M[i][j]);
		}
		printf("\n");
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <queue>
#include <string>

using namespace std;

const double PI = 3.14159265358979;

int G[101][101];


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

	for (int i = 0; i < n; i++)	{
		int id, degree;
		cin >> id >> degree;
		for (int j = 0; j < degree; j++) {
			int idx; cin >> idx;
			G[id][idx] = 1;
		}
	}

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


	return 0;
}

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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;
  vector< vector<int> > v(n, vector<int>(n, 0));
  for(int i = 0; i < n; i++){
    int u, k; cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      int a; cin >> a;
      a--;
      v[u][a] = 1;
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i == n-1 && j == n-1) cout << v[i][j];
      else cout << v[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int V, E;
vector<vector<int>> G;
vector<int> in_deg;
vector<bool> done;

bool solve()
{
    priority_queue<int, vector<int>, greater<int>> Q;

    rep(i, V) {
        if (in_deg[i] == 0) Q.push(i);
    }

    while (Q.size()) {
        int v = Q.top(); Q.pop();
        done[v] = true;

        for (int u : G[v]) {
            if (--in_deg[u] == 0) Q.push(u);
        }
    }

    rep(i, V) {
        if (in_deg[i] > 0) return true;
    }
    
    return false;
}

int main()
{
    cin >> V >> E;
    G.resize(V);
    in_deg.resize(V);
    done.resize(V);

    rep(i, E) {
        int S, T;
        cin >> S >> T;
        G[S].push_back(T);
        in_deg[T]++;
    }

    cout << solve() << endl;
}