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<stdio.h>
#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++)
    {
        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 a,b,c;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&a,&b);
        a--;
        for(int i=0;i<b;i++)
        {
            scanf("%d",&c);
            c--;
            M[a][c]++;
        }
    }
    dfs();
    return 0;
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

typedef long long ll;

ll d[100], f[100], now, cnt;
char flag[100];
vector<int> vec[100];

int dfs(int n) {
  if(flag[n]) return 0;
  flag[n] = 1;
  cnt++;
  d[n] = cnt;
  vector<int>::iterator it;
  for(it = vec[n].begin(); it != vec[n].end(); ++it) {
    if(!flag[*it]) dfs(*it);
  }
  ++cnt;
  f[n] = cnt;
  return 0;
}

int main(void) {
  ll n;
  scanf("%d", &n);
  now = 0, cnt = 0;
  rep(i, n) flag[i] = 0;
  rep(i, n) {
    int u, k;
    scanf("%d%d", &u, &k);
    u--;
    rep(j, k) {
      int v;
      scanf("%d", &v);
      v--;
      vec[u].push_back(v);
    }
    sort(vec[u].begin(), vec[u].end());
  }
  now = 0;
  while( 1 ) {
    dfs(now);
    int s = 1, i;
    for(i = 0; i < n; ++i) if(!flag[i]){
      s = 0;
      break;
    }
    if(s) break;
    else now = i;
    //rep(j, n) printf("%d ", (int)flag[j]);
    printf("%d\n", i);
    //return 0;
  }
  rep(i, n) printf("%d %lld %lld\n", i + 1, d[i], f[i]);
  return 0;
}

C++: //
//  main.cpp
//  DFS
//
//  Created by 2594345669 on 2016/12/05.
//  Copyright ?? 2016??´ as. All rights reserved.
//

#include <iostream>
using namespace std;

typedef pair<int, int> edge;

int vernum[101];
edge path[101][101];
int n;

edge found[101];

int t=1;
void dfs(int v){
    found[v].first = t;
    int i=0;
    while(1){
        if(!path[v][i].first)
            break;
        if(!found[path[v][i].second].first){
            t++;
            dfs(path[v][i].second);
            t++;
        }
        i++;
    }
    found[v].second = t+1;
}

int main() {
    int i, j;
    ios_base::sync_with_stdio(0);
    
    int e, v;
    cin >> n;
    
    for(i=1; i<=n; i++){
        cin >> vernum[i];
        cin >> e;
        for(j=0; j<e; j++){
            cin >> v;
            path[i][j] = make_pair(i, v);
        }
    }
    
    for(i=1; i<=n; i++){
        if(!found[i].first)
            dfs(i);
    }
    
    for(i=1; i<=n; i++){
        cout << vernum[i] << " " << found[i].first << " " << found[i].second << endl;
    }
    
    
    return 0;
}

C++: #include<iostream>
using namespace std;
int n,i,j,x,y,nx;
int map[100][100]={0};
int color[100]={0};//0 null  1 gray 2 black 
int start[100]={0};
int end[100]={0};
int pretime=0;
int dfs(int p){
	for(int m=0;m<n;m++){
		if(map[p][m]==1&&color[m]==0){
			start[m]=++pretime;
			color[m]=1;
			dfs(m);
		}
	}
	end[p]=++pretime;
	color[p]=2;
	return 0;
}
int main(){
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x>>nx;
		for(j=0;j<nx;j++){
			cin>>y;
			map[x-1][y-1]=1;
		}
	}
	for(i=0;i<n;i++){
		if(color[i]==0){
			color[i]=1;
		    start[i]=++pretime;
	     	dfs(i);
		}

	}

	for(i=0;i<n;i++){
		cout<<i+1<<" "<<start[i]<<" "<<end[i]<<endl;
	}
	
	
	return 0;
}