Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
//Graph I - Depth First Search
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

//WHITE -> ????¨?????????????
//GRAY  -> ?¨????????????????(?¨?????????????????¨???????????????????????????????????????§???????????????)
//BLACK -> ?¨??????????????????????(????¨???????????????????????????????????????????)

int n, M[N][N];
int color[N];//?????????????¨??????¶???
int d[N];//????????????
int f[N];//????????????
int tt;//time stamp

//?????°???????????±???????????¢?´¢
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()
{
	//??¨???????????????color???WHITE????¨????
	for( int u = 0; u < n; u++ ) color[u] = WHITE;
	tt = 0;
	for( int u = 0; u < n; u++ ){
		//????¨??????? u ?????°??????????§?????????¨????????±???????????¢?´¢
		if( color[u] == WHITE ) dfs_visit( u );
	}
	for( int u = 0; u < n; u++ ){
		cout << u + 1 << " " << d[u] << " " << f[u] << endl;
	}
}
int main()
{
	int u;//???????????????
	int k;//??????u?????£??\?????????????????????
	int v;//??????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;
		u--;
		for( int j = 0; j < k; j++ ){
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	dfs();
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
#include <list>

using namespace std;
int n;
list<int> adj[101];
int d[101] = {};
int f[101] = {};

void DFS(int v)
{
    static int num = 1;
    d[v] = num++;
    while (!adj[v].empty())
    {
        if (d[adj[v].front()] == 0)
            DFS(adj[v].front());
        adj[v].pop_front();
    }
    f[v] = num++;
}

void print()
{
    for (int i = 1; i <= n; i++)
    {
        printf("%d %d %d\n", i, d[i], f[i]);
    }
}

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

    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        while (k > 0)
        {
            cin >> v;
            adj[u].push_back(v);
            k--;
        }
    }

    DFS(1);

    print();

    return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
int n,graph[101][101],visit[101];
int d[101],f[101],t;
const int WHITE=0;
const int GRAY=1;
void dfs(int u){
    visit[u]=GRAY;
    d[u]=++t;
    FOR(v,1,n+1){
        if(graph[u][v]==0) continue;
        if(visit[v]==WHITE) dfs(v);
    }
    f[u]=++t;
    //printf("%d %d %d\n",u,d[u],f[u]);
}
int main(){
    int u,k,v;
    scanf("%d",&n);
    REP(i,n){
        scanf("%d%d",&u,&k);
        REP(j,k){
            scanf("%d",&v);
            graph[u][v]=1;
        }
    }
    FOR(i,1,n+1){
        if(visit[i]==WHITE) dfs(i);
    }
    FOR(i,1,n+1){
        printf("%d",i);
        printf(" %d %d\n",d[i],f[i]);
    }
    return 0;
}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n;
mat g;
vll d;
vll f;
vbl vis;

lli u,k,v;

lli dfs(lli x,lli t){
    d[x] = t;
    vis[x] = true;
    for(lli i = 0;i < g[x].size();i++){
        if(!vis[g[x][i]]) t = dfs(g[x][i],t+1);
    }
    return f[x] = t + 1;
}

int main(){
    cin >> n;
    g = mat(n+1);
    d = vll(n+1);
    f = vll(n+1);
    vis = vbl(n+1);
    for(lli i = 0;i < n;i++){
        cin >> u >> k;
        for(lli i = 0;i < k;i++){
            cin >> v;
            g[u].push_back(v);
        }
    }
    dfs(1,1);
    for(lli i = 1;i <= n;i++){
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

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