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;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 101;
enum Color { WHITE = 0, GRAY, BLACK};
int n, tt{0};
vv(int, M, MAX, MAX, 0);
vi color(MAX, 0), d(MAX, 0), f(MAX, 0);
inline void dfs_visit(int u) {
	color[u] = GRAY;
	d[u] = ++tt;
	rep(v, 0, n) {
		if(M[u][v] == 0) continue;
		if(color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}
inline void dfs() {
	rep(u, 0, n) {
		if(color[u] == WHITE) dfs_visit(u);
	}
	rep(u, 0, n) {
		cout << u + 1 << " " << d[u] << " " << f[u] << endl;
	}
}
int main() {
	cin >> n;
	int u, k, v;
	rep(i, 0, n) {
		cin >> u >> k;
		--u;
		rep(j, 0, k) {
			cin >> v;
			M[u][--v] = 1;
		}
	}
	dfs();
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <climits>
using namespace std;

#define MAX_N 101

int n, t;
vector<vector<int> > A(MAX_N, vector<int>(MAX_N, 0));
stack<int> S;
int d[MAX_N] = {};
int f[MAX_N] = {};

void df(int e)
{
    d[e] = t++;
    for (int i = 1; i <= n; i++) {
        if (A[e][i] && !d[i]) df(i);
    }
    f[e] = t++;
}

int main()
{
    int i, u, k, v;
    cin >> n;
    for (i = 0; i <= n; i++) A[0][i]++;
    for (i = 1; i <= n; i++) {
        cin >> u >> k;
        while (k--) {
            cin >> v;
            A[u][v]++;
        }
    }
    t = 0;
    df(0);
    for (i = 1; i <= n; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

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



using namespace std;




int main() {
	
	int n;
	cin>>n;
	vector<vector<int>>t(n,vector<int>(n));
	for(int i=0;i<n;i++){
		int x,r;cin>>r>>x;
		for(int j=0;j<x;j++){
			int w;cin>>w;w--;t[i].push_back(w);
			t[w].push_back(i);
		}
		sort(t[i].begin(),t[i].end());
	}
	for(int i=0;i<n;i++){
		sort(t[i].begin(),t[i].end());
	}
	stack<int>S;
	bool F[105]={};
	S.push(0);
	int p=1;
	F[0]=1;
	vector<int>G(n),H(n);
	int g=1;
	G[0]=1;
	while(S.size()){
		g++;
		int v=S.top();
		int a=-1;
		for(int i=0;i<t[v].size();i++){
			if(!F[t[v][i]]){
				a=t[v][i];break;
			}
		}
		if(a==-1){
			H[S.top()]=g;
			S.pop();
		}
		else{
			F[a]=1;
			G[a]=g;
			S.push(a);
		}
	}
	for(int i=0;i<n;i++){
		cout<<i+1<<" "<<G[i]<<" "<<H[i]<<endl;
	}
	

	
	return 0;
}

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

int n;
int g[101][101];
char c[101];
int visit[101];
int finish[101];
int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v;
            cin >> v;
            g[u][v] = 1;
        }

    }

   stack<int> s;
    for (int l = 1; l <= n; ++l) {
        c[l] = 'w';

    }
    int v = 1;
    s.push(1);
    c[1] = 'g';
    visit[1] = 1;
    int time = 1;
    while (s.size() != 0) {
        time++;
        v = s.top();
        int next = -1;
        for (int i = 1; i <= n ; ++i) {
            if(i == v) {
                continue;
            }
            if(g[v][i] && c[i] == 'w') {
                next = i;
                break;
            }
        }
        if(next == -1) {
            c[v] = 'b';
            finish[v] = time;
            s.pop();
        } else {
            c[next] = 'g';
            visit[next] = time;
            s.push(next);
        }
    }

    for (int m = 1; m <= n; ++m) {
        cout << m << " " << visit[m ] << " " << finish[m] << endl;

    }



    return 0;
}