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++: #define _CRT_SECURE_NO_WARNINGS
#define MAX 2000000000
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std ;

int d[102] = { 0 }, f[102] = { 0 };
int M[102][102];

int main() {
	stack<int> stk;
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++) {
		int k,l,m;
		cin >> m;
		cin >> k;
		for (int j = 0;j < k;j++) {
			cin >> l;
			M[m][l] = 1;
		}
	}
    
	stk.push(1);

    int i = 1,time=1;
    d[1]=1;
	while (!stk.empty()) {
		if (M[stk.top()][i] == 1 && d[i] == 0) {
			stk.push(i);
			time++;
			d[i] = time;
			i = 1;
		}
		else {
			i++;
			if (i > n) {
			    time++;
				f[stk.top()] = time;
				stk.pop();
				i=1;
			}
		}
	}

	for (int i = 1;i <= n;i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
  
}

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

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

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

C++: #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int n, t = 0;
vector<vector<int> > G(110);
pair<int, int> toki[110];
bool vis[110];

void dfs(int v)
{
    if(vis[v]) return;
    t++;
    toki[v].first = t;
    vis[v] = true;
    rep(i, G[v].size())
    {
        if(vis[G[v][i]]) continue;
        dfs(G[v][i]);
    }
    t++;
    toki[v].second = t;
    return;
}

int main(void)
{
    cin >> n;
    rep(i, n) vis[i] = false;
    rep(i, n)
    {
        int t, k;
        cin >> t >> k;
        t--;
        rep(j, k)
        {
            int v;
            cin >> v;
            v--;
            G[t].push_back(v);
        }
    }
    rep(i, n)
    {
        dfs(i);
    } 
    rep(i, n)
    {
        cout << i+1 << " " << toki[i].first << " " << toki[i].second << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int d[101],f[101],G[101][101];
stack<int>s;
int n,t;
void dfs(int u)
{
    s.push(u);
    d[u]=t++;
    int i;
    while(!s.empty()){
        u=s.top();
        for(i=1;i<=n;i++)
        {
            if(G[u][i]==1 && d[i]==0)
            {
                s.push(i);
                d[i]=t++;
                //u=i;
                break;
            }
        }
        if(i>n)
        {
            f[s.top()]=t++;
            s.pop();
        }
    }
}
int main()
{
    int k,u,v;
    cin>>n;
    for(int i=1;i<=n;i++){
        d[i]=0;
        for(int j=1;j<=n;j++)
            G[i][j]=0;
    }
    for(int i=0;i<n;i++)
    {
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            cin>>v;
            G[u][v]=1;
        }
    }
    t=1;
    for(int i=1;i<=n;i++)
    {
        if(d[i]==0)
            dfs(i);
    }
    for(int i=1;i<=n;i++)
    {
        cout<<i<<' '<<d[i]<<' '<<f[i]<<endl;
    }
    return 0;
}