Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include<bits/stdc++.h>
//cout<<setprecision(1)<<fixed<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N=100000;
const int INF = 0x3f3f3f3f;
#define eps 1e-7
//#define Kongxiangzhouye
int n;
int a[123][123];
int st[123];
int ed[123];
int now;
void dfs(int local){
	st[local]=now++;
	int flag=1;
	for(int i=1;i<=n;i++){
		if(a[local][i]==1){
			if(st[i]==0){
				flag=0;
				dfs(i);
			}
		}
	}
	ed[local]=now++;
}
int main(){
	ios::sync_with_stdio(false);
	#ifdef Kongxiangzhouye
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	while(cin>>n){
		memset(a,0,sizeof(a));
		memset(st,0,sizeof(st));
		memset(ed,0,sizeof(ed));
		for(int i=0;i<n;i++){
			int t,m;
			cin>>t>>m;
			for(int i=0;i<m;i++){
				int te;
				cin>>te;
				a[t][te]=1;
			}
			now=1;
		}
		dfs(1);
		for(int i=1;i<=n;i++){
			cout<<i<<" "<<st[i]<<" "<<ed[i]<<endl;
		}
	}
	return 0;
}

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

int n;
int cnt1 = 0; 
vector<int> d(n);
vector<int> f(n);
void dfs(const Graph &G, int v){
    cnt1++;
    d[v - 1] = cnt1;
    for(auto nv : G[v - 1]){
        if(d[nv - 1] != 0) continue;
        dfs(G, nv);
    }
    cnt1++;
    f[v - 1] = cnt1;
}

int main(){
    cin >> n;
    Graph G(n); 
    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        if(b == 0) continue;
        for(int j = 0; j < b; j++){
            int x; cin >> x;
            G[a - 1].push_back(x);
        }
    }
    d.assign(n, 0);
    f.assign(n, 0);
    for(int i = 1; i <= n; i++){
      if(d[i - 1] == 0) dfs(G, i);
    }
    for(int i = 1; i <= n; i++){
        cout << i << " " << d[i - 1] << " " << f[i - 1] << endl; 
    }
}

C++: #include <iostream>
#define MAX 101

using namespace std;

bool flag[MAX][MAX];
int t[MAX][2];
int n;

void dfs(int num){
	static int cnt = 1;
	
	if(t[num][0] == 0)t[num][0] = cnt++;
	else return;
	for(int i=1;i<=n;++i){
		if(flag[num][i] == true){
			dfs(i);
		}
	}
	t[num][1] = cnt++;
}

int main(){
	int u, k, v, i, j; 
	
	cin >> n;
	for(i=1;i<=n;++i){
		cin >> u >> k;
		for(j=0;j<k;++j){
			cin >> v;
			flag[u][v] = true;
		}
		 
	}
	for(int i=1;i<=n;++i)dfs(i);
	for(int i=1;i<=n;++i)cout << i << " " << t[i][0] << " " << t[i][1] << endl;
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

using Graph = vector<vector<ll>>;
Graph G;
ll d[110], f[110];

void DFS(ll v, ll &t)
{
	if (d[v] != -1) return;
	d[v] = t;

	++t;
	for (auto &nv : G[v])
	{
		DFS(nv, t);
	}
	f[v] = t;
	++t;
}

int main(int argc, char **argv)
{
	ll N; cin >> N;
	G.resize(N);
	for (ll i = 0; i < N; ++i)
	{
		ll n, k; cin >> n >> k;
		--n;
		for (ll j = 0; j < k; ++j)
		{
			ll v; cin >> v;
			--v;
			G[n].push_back(v);
		}
		sort(G[n].begin(), G[n].end());
	}
	fill(d, d+110, -1);
	fill(f, f+110, -1);

	ll t = 1;
	for (ll v = 0; v < N; ++v)
	{
		if (d[v] == -1)
			DFS(v, t);
	}

	for (ll i = 0; i < N; ++i)
	{
		std::cout << i + 1 << " " << d[i] << " " << f[i] << std::endl;
	}
}

C++: //?????????????????¢?´¢
//??????????????????????????????????????¢?´¢
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

//u?????£??\??????v?????????????????¨???
int next(int u){
    for(int v = nt[u]; v < n; v++){
        nt[u] = v + 1;
        if(M[u][v]) return v;
    }
    return -1;
}

void dfs_visit(int r){
    for(int i = 0; i < n; i++) nt[i] = 0;
    stack<int> S;
    
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;
    
    while(!S.empty()){
        int u = S.top();
        int v = next(u);
        
        if(v != -1){
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }
        else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs(){
    int u;
    for(int i = 0; i < n; i++) nt[i] = 0;
    
    for( u = 0; u < n; u++){
        //????¨????u?????¢??????????????????dfs
        if(d[u] == WHITE) dfs_visit(u);
    }
    
    for( int i = 0; i < n; i++){
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main(void){
    int u, v, k, j,i;
    
    cin >> n;
    
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++) M[i][j] = 0;
   
    for(i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for(j = 0; j < k; j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
    
    return 0;
}

C++: #include <iostream>
#include <stack>

using namespace std;

#define MAX 110
int num;
int matrix[MAX][MAX];
int dst[MAX];

void input(){
    cin >> num;
    for(int i=0;i<MAX;i++){
        dst[i] = -1;
        for(int j=0;j<MAX;j++){
            matrix[i][j] = 0;
        }
    }
    for(int i=1;i<=num;i++){
        int v; cin >> v;
        int tmp; cin >>tmp;
        for(int j=0;j<tmp;j++){
            int vi; cin >> vi;
            matrix[v-1][vi-1] = 1;
        }
    }
}

void dfs(){
    stack<int> S;
    S.push(0);
    dst[0] = 0;
    while(S.size() != 0){
        int cur = S.top();
        S.pop();
        for(int i=0;i<num;i++){
            if(matrix[cur][i]==1){
                if(dst[i]==-1 ){
                    S.push(i);
                    dst[i] = dst[cur] + 1;
                }
            }
        }
    }
    for(int i=0;i<num;i++){
        cout << i+1 << " " <<  dst[i] << endl;
    }
}

int main(){
    input();
    dfs();
}