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

	timer := 1
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	return x
}

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 <cstdio>
#include <stack>

#define N 100

using namespace std;

int d[N],f[N],m[N][N],ucolor[N],t,n,nt[N];

int next(int u2){
	int r;
	for(r=nt[u2];r<n;r++){
		nt[u2] = r+1;
		if(m[u2][r]){
			return r;
		}
	}
	return -1;
}

void dfsvisit(int uu){
	int u3=0,v,i;
	for(i=0;i<n;i++){
		nt[i] = 0;
	}
	stack<int> s;
	s.push(uu);
	ucolor[uu] = 1;
	d[uu] = ++t;
	while( !s.empty() ){
		u3 = s.top();
		v = next(u3);
		if(v != -1){
			if(ucolor[v] == 0){
				ucolor[v] = 1;
				d[v] = ++t;
				s.push(v);
			}
		}else{
			s.pop();
			ucolor[u3] = 2;
			f[u3] = ++t;
		}
	}
}

void dfs(){
	int i,j;
	for(i=0;i<n;i++){
		ucolor[i] = 0;
		nt[i] = 0;
	}
	for(j=0;j<n;j++){
		if(ucolor[j]==0){
			dfsvisit(j);
		}
	}
	for(i=0;i<n;i++){
		printf("%d %d %d\n",i+1,d[i],f[i]);
	}
}

int main(void){
	int i,j,u1,k,box;
	t = 0;// 時間の初期化
	for(i=0;i<N;i++){
		for(j=0;j<N;j++)m[i][j]=0;
	}
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&u1,&k);
		u1--; //頂点番号、その隣接する頂点の数
		for(j=0;j<k;j++){
			scanf("%d",&box);
			box--; // 隣接する頂点の番号
			m[u1][box] = 1;
		}
	}
	dfs();
	return 0;
}

C++: //
//  main.cpp
//  619
//
//  Created by 8595198919 on 14/06/16.
//  Copyright (c) 2014年 8595198919. All rights reserved.
//

#define _2
#ifdef _1
#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;

int dist[105];
queue<int> que;
vector<int> G[105];
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        dist[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    que.push(1);
    dist[1]=0;
    while(!que.empty()){
        int now = que.front();
        que.pop();
        int d = dist[now];
        rep(i,G[now].size()){
            if(dist[G[now][i]]==-1){
                dist[G[now][i]]=d+1;
                que.push(G[now][i]);
            }
        }
    }
    for(int i = 1;i <= n;i++) {
        cout <<i <<" " << dist[i]<<endl;
    }
}
#endif

#ifdef _2

#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;


vector<int> G[105];
int d[105];
int f[105];
int tm = 1;
void dfs(int p){
    d[p]=tm;
    rep(i,G[p].size()){
        if(d[G[p][i]]==-1){
            tm++;
            dfs(G[p][i]);
        }
    }
    f[p] = ++tm;
    return;
}
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        d[i]=-1;
        f[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    dfs(1);
    for(int i = 1;i <= n;i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }
}

#endif

C++: #include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;
#define N 100
int n, m[N][N];
int color[N], d[N], f[N], tt;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
void dfs_visit(int i){
    color[i] = 1;
    d[i] = ++tt;
    for(int j = 0; j < n; j++){
        if(m[i][j] == 0){
            continue;
        }
        if(color[j] == 0){
            dfs_visit(j);
        }
    }
    color[i] = 2;
    f[i] = ++tt;
}
void dfs(){
    for(int i = 0; i < n; i++){
        color[i] = 0;
    }
    tt = 0;
    for(int i = 0; i < n; i++){
        if(color[i] == 0){
            dfs_visit(i);
        }
    }
    for(int i = 0; i < n; i++){
        cout << i+1 << " "<<  d[i] << " " << f[i] << endl;
    }
}
int main(){
    //std::stack<int> stack;
    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;
        }
    }
    dfs();
    //cout << masu << endl;
    return 0;
}

C++: #include <cstdio>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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

//??¨???????????°?????°?????±?????????????´¢
void dfs_visit(int u){
    int v;
    color[u]=GRAY;
    //???????????????
    d[u]=++tt;
    for(v=0;v<n;v++){
        if(M[u][v]==0)
            continue;
        if(color[v]==WHITE)
            dfs_visit(v);
    }
    color[u]=BLACK;
    //????????????
    f[u]=++tt;
}

void dfs(){
    int u;
    //????§????
    for(u=0;u<n;u++)
        color[u]=WHITE;
    tt=0;
    
    for(u=0;u<n;u++)
        //??\????????????u?????????????????±?????????????´¢
        if(color[u]==WHITE)
            dfs_visit(u);
    for(u=0;u<n;u++)
        printf("%d %d %d\n",u+1,d[u],f[u]);
}

int main(){
    int u,v,k;
    
    scanf("%d",&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++){
        scanf("%d %d",&u,&k);
        u--;
        for(int j=0;j<k;j++){
            scanf("%d",&v);
            v--;
            M[u][v]=1;
        }
    }
    
    dfs();
}