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

const int MAX=200;

int state[MAX],d[MAX],f[MAX],N;
vector<int> T[MAX];
stack<int> S;

void DFS(){
    int time=0,count=0;
    while(count!=N){
        for(int j=0;j<N;j++){
            if(state[j]==0){
                S.push(j);
                state[j]=1;
                time++;
                d[j]=time;
                break;
            }
        }
    while(S.size()){
        int a=S.top();
        bool flag=true;
        for(int i=0;i<T[a].size();i++){
            if(state[T[a][i]]==0){
                S.push(T[a][i]);
                state[T[a][i]]=1;
                time++;
                d[T[a][i]]=time;
                flag=false;
                break;
            }
        }
            if(flag){
                time++;
                state[a]=2;
                count++;
                f[a]=time;
                S.pop();
            }
            
        }
    }
    for(int i=0;i<N;i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

int main(){
   
    int u,k,a;cin>>N;
    
    for(int i=0;i<N;i++){
        state[i]=0;
        d[i]=0;
        f[i]=0;
    }
    
    for(int i=0;i<N;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>a;
            a--;
            T[u].push_back(a);
        }
    }
    DFS();
}

C++: #include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<stack>
#define MAX 105
#define WT 0
#define GR 1
#define BK 2

using namespace std;

int M[MAX][MAX];
int cr[MAX], d[MAX], f[MAX];
int t;
stack<int> ck;
void dfs_init(int n)
{
    t = 1;

    for(int i = 1; i <= n; i++)
        cr[i] = WT;

    return;
}
void dfs(int k,int n)
{
    if(cr[k] == WT)
    {
        cr[k] = GR;
        d[k] = t;
        t++;
        ck.push(k);

        for(int i = 1; i <= n; i++)
        {
            if(M[k][i] == 1 && cr[i] == WT)
                dfs(i,n);
            else if(i == n)
            {
                dfs(ck.top(),n);ck.pop();
            }
        }
    }
    else if(cr[k] == GR)
    {
        ck.pop();
        cr[k] = BK;
        f[k] = t;
        t++;

        if(!ck.empty())
            dfs(ck.top(),n);
        else
            return;
    }
}
int main()
{
    int i, j, n, p, q, tmp;

//Set the matrix: M[n][n]
    for(i = 0; i < MAX; i++)
        for(j = 0; j < MAX; j++)
            M[i][j] = 0;

    scanf("%d", &n);

    for(i = 0; i < n; i++)
    {
        scanf("%d%d", &p, &q);

        for(j = 0; j < q; j++)
        {
            scanf("%d", &tmp);
            M[p][tmp] = 1;
        }
    }

    //DFS:d[v] and f[v] for start and end
    dfs_init(n);
    dfs(1,n);

    for(i = 1; i <= n; i++)
        printf("%d %d %d\n", i, d[i], f[i]);

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
vector<bool>seen(1000,false);
vector<pair<int,int>>ans(1000);
vector<int>first_order(1000,10e7),last_order(1000,10e7);
void dfs(const vvll &gura, int v, int& now) {
    first_order[v] = min(first_order[v],now++);

    seen[v] = true; 
    for (auto next_v : gura[v]) { 
        if (seen[next_v]) continue;
        dfs(gura, next_v, now);
    }

    last_order[v] = min(last_order[v],now++);
}
int main(){
    int n;
    cin >> n;
    vvll gura(n);
    for(int i=0;i<n;i++){
        int ww; cin >>ww;
        int w;
        cin >> w;
        for(int j=0;j<w;j++){
            int d;
            cin >> d;
            gura.at(i).push_back(d-1);
        }
    }
    int now = 1;
    for(int i=0;i<n;i++){
        if(seen[i])continue;
    dfs(gura,i,now);
    }
    for(int i=0;i<n;i++){
        cout << i+1<<" "<< first_order[i]<<" "<<last_order[i]<<endl;
    }
}