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

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>

using namespace std;


struct Edge{ //??°????????????
public:
    int src, dst;
    int weight;
    Edge(int a,int b):src(a),dst(b),weight(1){} //?????????????????????
    void setWeight(double x){
        weight = x;
    }
};
typedef vector<Edge> Edges; //???????????£??\?????????
typedef vector<Edges> Graph; //??°???????????£??\???????????¨???

typedef vector<int> Array; //??´??°?????????
typedef vector<Array> Matrix; //??´??°???????????£??\?????????

const int N = 100;
const int White = 0, Gray = 1, Black =2;

int n;
int tt = 0;
Matrix M(N,Array(N,0));
vector<int> d(N,0), f(N,0);
vector<int> color(N,0);


vector<int> nt(N,0);//???????????????????????????????????§?????????????¨???¶??????

int next(int u){ //???u?????\?¶??????????????????????????????????
    if (nt[u]!= n) {
        for(int i = nt[u];i<n;i++){
            if(M[u][i]){
                nt[u] = i+1;
                return i;
            }
        }
        return -1;
    } else {
        return -1;
    }
}

void dfs_visit(int r){
    for (int i= 0; i<n; i++) {
        nt[i] = 0;
    }
    
    stack<int> S;
    S.push(r);
    color[r] = Gray;
    d[r] = ++tt;
    
    while (!S.empty()) {
        int v = S.top();
        int w = next(v);
        if (w != -1) {
            if (color[w]==White) {
                color[w] = Gray;
                d[w] = ++tt;
                S.push(w);
            }
        } else {
            S.pop();
            color[v] = Black;
            f[v] = ++tt;
        }
    }
    
}

void dfs(){
    for (int i = 0; i<n; i++) {
        color[i] = White;
        nt[i] = 0;
    }
    for (int i = 0; i<n; i++) {
        if (color[i]==White) {
            dfs_visit(i);
        }
    }
    for (int i = 0; i<n; i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}


int main(){
    
    int k,v,w;
    
    cin >> n; //??°????????????????????\???
    
    for (int i=0; i<n; i++) { //??????????¬???°?????????????????\??? ???????????\??????????????£??\??????????????£??\?????????????´?
        cin >> w >> k;
        for (int j=0; j<k; j++) {
            cin >> v;
            M[w-1][v-1] = 1; //?????????
        }
    }
    
    dfs();
    
    return 0;
}