Go: package main

/*
深さ優先探索
*/

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

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n+1)
	for i := 1; i < n+1; i++ {
		ints := eGetInts(scanner)
		num, vcount := ints[0], ints[1]
		g[i] = make([]int, vcount)
		for j := 0; j < vcount; j++ {
			g[num][j] = ints[j+2]
		}
	}
	hist := make([]struct{ d, f int }, n+1)
	t := 0
	var visit func(int)
	visit = func(num int) {
		if hist[num].d == 0 {
			stack := []int{}
			t++
			hist[num].d = t
			stack = append(stack, num)
			for len(stack) > 0 {
				// トップを訪問する
				top := stack[len(stack)-1]
				for i := 0; i < len(g[top]); i++ {
					if hist[g[top][i]].d == 0 {
						t++
						hist[g[top][i]].d = t
						stack = append(stack, g[top][i])
						goto endloop
					}
				}
				// 訪問場所がなくなったら
				// pop
				stack = stack[0 : len(stack)-1]
				t++
				hist[top].f = t
			endloop:
			}
		}
	}
	for i := 1; i < n+1; i++ {
		visit(i)
	}
	for i := 1; i < n+1; i++ {
		fmt.Println(i, hist[i].d, hist[i].f)
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define nyan "(=^･ω･^=)"
using namespace std;

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
//using ll = long long;
//using P = pair<int,int>;

int n;
int M[110][110];
int visited[110];
vector<int> d(110, 0);
vector<int> f(110, 0);
int t;

void dfs(int v){
    
    t++;
    d[v] += t;
    visited[v] = 1;
    
    for (int i = 0; i < n; i++){
        if (M[v][i] == 0) continue;
        
        if(visited[i] == 0) dfs(i);
    }
    
    visited[v] = 2;
    t++;
    f[v] += t;
}

int main(){
    cin >> n;
    t = 0;
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++) M[i][j] = 0;
        visited[i] = 0;
    }
    
    for (int i = 0; i < n; i++){
        int u;
        cin >> u;
        u--;
        
        int k;
        cin >> k;
        
        for (int j = 0; j < k; j++){
            int v;
            cin >> v;
            v--;
            
            M[u][v]++;
        }
    }
    
    for (int i = 0; i < n; i++){
        if (visited[i] == 0) dfs(i);
    }
    
    for (int i = 0; i < n; i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    
    
}

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

vector<vector<int> > list(100);
vector<vector<int> > timed(100);
int times;
void dfs(int now){
	if(!timed[now].empty())	return;
	timed[now].push_back(times++);
	for(int i=0;i<(int)list[now].size();i++){
		dfs(list[now][i]);
	}
	timed[now].push_back(times++);
}

int main(){
	int n;	cin>>n;
	int id,num,ne;
	for(int i=0;i<n;i++){
		cin>>id>>num;
		id--;
		for(int j=0;j<num;j++){
			cin>>ne;
			list[id].push_back(ne-1);
		}
	}
	times=1;
	for(int i=0;i<n;i++){
		if(timed[i].empty())	dfs(i);
	}
	for(int i=0;i<n;i++){
		cout<<i+1;
		for(int j=0;j<(int)timed[i].size();j++){
			cout<<" "<<timed[i][j];
		}
		cout<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <stack>
#define N 110
using namespace std;
int n;
int m[N][N];
int used[N];
int time = 1;
int bb_start[N];
int bb_end[N];
int getnext(int u){
    for(int i = 1; i <= n; i++){
        if(m[u][i] == 1) return i;
    }
    return -1;
}
void dfs(int root){
    used[root] = 1;
    bb_start[root] = time++;
    stack<int> s;
    s.push(root);
    while(!s.empty()){
        int u = s.top();
        int v = getnext(u);
        if(v != -1 && used[v] == 0){
            used[v] = 1;
            bb_start[v] = time++;
            s.push(v);
        } else{
            bb_end[u] = time++;
            s.pop();
        }
    }
}
int main(){
    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++) used[i] = 0;
    scanf("%d", &n);
    for(int p = 0; p < n; p++){
        int node, k;
        scanf("%d %d", &node, &k);
        for(int i = 0; i < k; i++){
            int b;
            scanf("%d", &b);
            m[node][b] = 1;
        }
    }
    for(int i = 1; i <= n; i++) if(used[i] == 0) dfs(i);
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, bb_start[i], bb_end[i]);
    }
    return 0;
}

C++: #include <stdio.h>
#define MAX 101

int n, ni = 1;
int A[MAX][MAX] = {0}, a[MAX] = {0}, b[MAX] = {0};

void serch(int x){
  int i;
  
  a[x] = ni++;
  for(i=1; i<=n; i++){
    if(a[i] == 0 && A[x][i] == 1)
      serch(i);
  }
  b[x] = ni++;
}

int main(){
  int i, j, k, x, y;
  
  scanf("%d", &n);
  for(i=1; i<=n; i++){
    scanf("%d%d", &x, &k);
    for(j=1; j<=k; j++){
      scanf("%d", &y);
      A[x][y] = 1;
    }
  }
 
  for(i=1; i<=n; i++){
    if(a[i] == 0)
      serch(i);
  }
  
  for(i=1; i<=n; i++){
    printf("%d %d %d\n", i, a[i], b[i]);
  }
 
  return 0;
}

C++: #include<iostream>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
using namespace std;
int G[100][100] = {};
int timer = 0;
typedef struct ANS
{
	int id, t, e;
	bool done;
};

void rec(ANS a[],int t)
{
	timer++;
	a[t].t = timer;
	a[t].done = true;
	FOR(i, 0, 100)
	{
		if (G[t][i] == 1 && a[i].done == false)
		{
			rec(a, i);
		}
	}
	timer++;
	a[t].e = timer;
}

int main()
{
	ANS ans[101];
	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		ans[i].id = i + 1;
		ans[i].done = false;
		int u, m;
		cin >> u >> m;
		FOR(j, 0, m)
		{
			int l;
			cin >> l;
			G[u - 1][l - 1] = 1;
		}
	}
	rec(ans, 0);
	FOR(i, 0, n)
	{
		cout << ans[i].id << " " << ans[i].t << " " << ans[i].e << endl;
	}
	return 0;
}