Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), -1}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}
	nodes[1].depth = 0

	walk(1, 0, &nodes)
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v\n", (*nodes[i]).id, (*nodes[i]).depth)
	}
}

var time int
var record [100][100]bool
var q Queue

func walk(nid int, from int, nodes *map[int]*node) {
	q.Enqueue((*nodes)[nid])
	for !q.IsEmpty() {
		n := q.Dequeue().(*node)
		for _, v := range n.nexts {
			n2 := (*nodes)[v]
			if n2.depth != -1 {
				continue
			}
			n2.depth = n.depth + 1
			q.Enqueue((*nodes)[v])
		}
	}
}

type node struct {
	id    int
	nexts []int
	depth int
}

// Queue is Queue
type Queue struct {
	val []interface{}
}

// Enqueue value
func (queue *Queue) Enqueue(val interface{}) {
	queue.val = append(queue.val, val)
}

// Dequeue value
func (queue *Queue) Dequeue() interface{} {
	res := queue.val[0]
	queue.val = queue.val[1:len(queue.val)]
	return res
}

// IsEmpty return true when queue is empty
func (queue *Queue) IsEmpty() bool {
	return len(queue.val) == 0
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int main(){
   int n,u,v,k,inf = -1;
   cin >> n;
   vector<int> a(n,0),D(n,inf);
   vector<vector<int> > edges(n,a); 
   for(int i = 0;i < n;i++){
       cin >> u;
       cin >> v;
       for(int ii = 0;ii < v;ii++){
           cin >> k;
           edges[u-1][k-1] = 1;
       }
   }
   queue<int> Q;
   Q.push(0);
   D[0] = 0;
   while(!Q.empty()){
        int cur = Q.front();
        Q.pop();//最初の要素を削除、詰める
        for(int dst = 0;dst < n;dst++){
            if(edges[cur][dst] == 1 && D[dst] == inf){
                D[dst] = D[cur] + 1;
                Q.push(dst);
            }
        }
   }
   for(int i = 0;i < n;i++){
       cout << i+1 << " " << D[i] << endl;
   }
}

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

queue<pair<int,int> > qu;
vector<int> v[111];
int root;
int b[111];
int d[111];
pair<int, int> pa;
int g;

void wide(int num){

  memset(d,-1,sizeof(d));
  d[num] = 0;
  qu.push(make_pair(num,d[1]));

  while(!qu.empty()){

    qu.front();
    pa = qu.front();
    qu.pop();
    int id = pa.first;

    for(int i = 0; i < (int)v[id].size(); i++){
      if(d[v[id][i]] == -1){
	d[v[id][i]] = pa.second + 1;
	qu.push(make_pair(v[id][i],d[v[id][i]]));
      }
    }
  }
  for(int i = 1; i <= g; i++){
    cout << i << " " << d[i] << endl;
  }

}

int main(){

 
  cin >> g;
  int n;
  for(int i = 0; i < g; i++){
    cin >> n >> b[i];
    for(int j = 0; j < b[i]; j++){
      cin >> root;
      v[n].push_back(root);
      v[root].push_back(n);
    }
  }

  wide(1);

}

C++: #include <iostream>
#include <climits>
#include <queue>

static const int N=100;

int n,M[N][N];
int d[N];

using namespace std;
void bfs(int s)
{
    queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++) d[i]=INT_MAX;
    d[s]=0;
    int u;
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        for(int v=0;v<n;v++)
        {
            if(M[u][v]==0) continue;
            if(d[v]!=INT_MAX) continue;
            d[v]=d[u]+1;
            q.push(v);
         }
    }
    for(int i=0;i<n;i++)
    {
        cout<<i+1<<" "<<((d[i]==INT_MAX)?(-1):d[i])<<endl;
    }
}

int main()
{
    int u,k,v;
    cin>>n;

    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;
        }
    }
    bfs(0);
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

vector<int> d, color;
vector<vector<int>> A;

void bfs() {
    queue<int> q;
    q.push(0);
    d[0] = 0;
    color[0] = 1;
    while (!q.empty()) {
        int i = q.front(); q.pop();
        for (auto j : A[i]) {
            if (color[j] == 0) {
                q.push(j);
                d[j] = d[i] + 1;
                color[j] = 1;
            }
        }
    }
}

int main() {
    int n;
    cin >> n;
    A = vector<vector<int>>(n, vector<int>(0));
    d = vector<int>(n, -1);
    color = vector<int>(n, 0);
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        rep(j, k) {
            int tmp;
            cin >> tmp;
            A[i].push_back(--tmp);
        }
    }
    bfs();
    rep(i, n) {
        printf("%d %d\n", i + 1, d[i]);
    }
    return 0;
}

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

struct edge{
    int node;
    edge *next;
}nodes[105];

int n,d[105],v[105];
queue<edge> E;

void bfs(){
    edge *e=E.front().next;
    while(e!=NULL){
        int num=e->node;
        if(v[num]==0){
            v[num]=1;
            d[num]=d[E.front().node]+1;
            E.push(nodes[num]);
        }
        e=e->next;
    }
    E.pop();
}

int main(){
    memset(v,0,sizeof(v));
    memset(d,-1,sizeof(d));
    cin>>n;
    int i,j;
    for(i=1;i<=n;i++){
        int ii,n_i;
        cin>>ii>>n_i;
        nodes[ii].node=ii;
        edge *first=&nodes[ii];
        for(j=0;j<n_i;j++){
            edge *e=new edge();
            cin>>e->node;
            first->next=e;
            first=e;
        }
    }
    d[1]=0;
    v[1]=1;
    E.push(nodes[1]);
    while(E.size()!=0){
        bfs();
    }
    for(i=1;i<=n;i++)cout<<i<<" "<<d[i]<<endl;
    return 0;
}

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

static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N];

void bfs(int s) {
  queue<int> q;
  q.push(s);
  for (int i = 0; i < n; i++) d[i] = INFTY;
  d[s] = 0;
  int u;
  while ( !q.empty() ) {
    u = q.front();
    q.pop();
    for (int v = 0; v < n; v++) {
      if (M[u][v] == 0) continue;
      if ( d[v] != INFTY) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }

  for (int i = 0; i < n; i++) {
    cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
  }
}

int main() {
  int u, k, v;

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

  bfs(0);

  return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N], d[N];

void bfs(int s) {
	queue<int> q;
	q.push(s);
	for(int i = 0; i < n; i++) {
		d[i] =INFTY;
	}
	d[s] = 0;
	int u;
	while(!q.empty()) {
		u = q.front();
		q.pop();
		for(int v = 0; v < n; v++) {
		    if(M[u][v] == 0) continue;
		    if(d[v] != INFTY) continue;
		    d[v] = d[u] + 1;
		    q.push(v);
	    }
    }
    for(int i = 0; i < n; i++) {
    	cout << i + 1 << " " << ( (d[i] == INFTY) ? -1 : d[i] ) << endl;
    }

}

int main() {
	int v, k ,u;
	cin >> n;
	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;
		for(int j = 0; j < k; j++) {
			cin >> v;
			M[u-1][v-1] = 1;
		}
	}
	
	bfs(0);
	
	return 0;
	
}