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 <iostream>
using namespace std;

static const int MAX_N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int N;
int G[MAX_N][MAX_N];
int color[MAX_N], d[MAX_N], f[MAX_N];
int t;

void bfs_visit(int u) {
    color[u] = GRAY;
    d[u] = ++t;
    for (int i = 0; i < N; i++) {
        if (G[u][i] && color[i] == WHITE) {
            bfs_visit(i);
        }
    }
    color[u] = BLACK;
    f[u] = ++t;
}

void dfs() {
    for (int i = 0; i < N; i++) {
        color[i] = WHITE;
    }
    t = 0;
    for (int i = 0; i < N; i++) {
        if (color[i] == WHITE) {
            bfs_visit(i);
        }
    }
    for (int i = 0; i < N; i++) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            v--;
            G[u][v] = 1;
        }
    }

    dfs();
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> v(101);
int dp[101][2] = { 0 };
int n, t = 0;

void dfs(int a) {
	t++;
	if (dp[a][0] == 0) { dp[a][0] = t; }
	for (int i = 0;i < v[a].size();i++) {
		if (dp[v[a][i]][0] == 0) {
			dfs(v[a][i]);
		}
	}
	t++;
	if (dp[a][1] == 0) { dp[a][1] = t; }
}

int main() {
	cin >> n;
	for (int i = 0; i < n;i++) {
		int u,k; cin >> u >> k;
		for (int j = 0; j < k;j++) {
			int x; cin >> x;
			v[u].push_back(x);
		}
	}
	dfs(1);
	for (int i = 1; i <= n;i++) {
		cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << endl;
	}
}

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

#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 visit(int a){
  int b;
  color[a]=GRAY;
  d[a]=++tt;
  for(b=0;b<n;b++){
    if(m[a][b]==0) continue;
    if(color[b]==WHITE) visit(b);
  }
  color[a]=BLACK;
  f[a]=++tt;
}

void dfs(){
  int a;
  for(a=0;a<n;a++) color[a]=WHITE;

  tt=0;

  for(a=0;a<n;a++){
    if(color[a]==WHITE) visit(a);
  }
  for(a=0;a<n;a++) printf("%d %d %d\n",a+1,d[a],f[a]);

}

int main(){
  int u,v,k,i,j;

  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<vector>
#include<algorithm>
using namespace std;
bool graph[101][101];
int first_time[101],last_time[101];
int visited[101];
int tt=0;
int v[101][101];
#define white 0
#define gray 1
#define black 2//0回目の訪問、1回目の訪問、2回目の訪問の3種類あるからboolを使わない

void dfs(int v,int n) {
	for (int i = 2; i <= n; ++i) {
		if (graph[v][i] == false)continue;
		if (visited[i] == white) {
			visited[i] = gray;
			++tt;
			first_time[i] = tt;
			dfs(i, n);
		}
	}
	visited[v] = black;
	++tt;
	last_time[v] = tt;

}

int main() {
	int n;
	cin >> n;
	int u, k;
	for (int i = 0; i < n; ++i) {
		cin >> u >> k;
		for (int j = 0; j < k; ++j) {
			cin >> v[u][j + 1];
			graph[u][v[u][j + 1]] = true;
		}
	}
	for (int i = 1; i <= n; ++i) {//1つの始点から全訪問可能とは限らないから
		if (visited[i] == white) {
			visited[i] = gray;
			++tt;
			first_time[i] = tt;
			dfs(i, n);
		}
	}
	for (int i = 1; i <= n; ++i) {
		cout << i << " " << first_time[i] << " " << last_time[i] << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAX_NODE 101

int begin_times[MAX_NODE];
int end_times[MAX_NODE];
int c_time=0;
queue<int> g[MAX_NODE];

void dfs(int f){
  if(begin_times[f]>0)return;
  c_time++;
  begin_times[f]=c_time;
  while( !g[f].empty() ){
    int to = g[f].front();
    g[f].pop();
    if(end_times[to]>0)continue;
    dfs(to);
  }
  c_time++;
  end_times[f]=c_time;
}

int main(){
  int n;cin>>n;
  rep(i, n){
    int from;
    int count;
    cin>>from>>count;
    rep(j, count){
      int t;cin>>t;
      g[from].push(t);
    }
  }

  rep1(i, n)dfs(i);

  rep1(i, n){
    cout<<i<<' '<<begin_times[i]<<' '<<end_times[i]<<endl;
  }

  return 0;
}