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

#define MAX 100

#define WHITE 0
#define GRAY 1
#define BLACK 2

int T;
int N;

int M[MAX][MAX];
int D[MAX], F[MAX], C[MAX];

void dfs(int u)
{
    C[u] = GRAY;
    D[u] = ++T;

    for (int i = 0; i < N; i++)
    {
        if(M[u][i] == 1 && C[i] == WHITE)
        {
            dfs(i);
        }        
    }
    C[u] = BLACK;
    F[u] = ++T;
}

int main ()
{
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        D[i] = 0;
        F[i] = 0;
        C[i] = WHITE;
        
        for (int j = 0; j < N; j++)
        {
            M[i][j] = 0;
        }
    }

    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--;
            M[u][v] = 1;
        }
    }

/*
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (j > 0)
                cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
*/
    T = 0;

    for (int i = 0; i < N; i++)
    {
        if (C[i] == WHITE)
        {
            dfs(i);
        }
    }

    /*
    stack<int> *S = new stack<int>;


    S->push(0);
    C[0] = GRAY;
    D[0] = ++time;

    while (S->size() > 0)
    {
        int u = S->top();
        int v = -1;

        // next 
        for (int i = 0; i < N; i++)
        {
            if (M[u][i] == 1)
            {
                if (C[i] == WHITE)
                {
                    v = i;
                    break;
                }
            }
        }

        if (v != -1)
        {
            C[v] = GRAY;
            D[v] = ++time;
            S->push(v);
        }
        else
        {
            S->pop();
            C[u] = BLACK;
            F[u] = ++time;
        }
    }
*/

    for (int i = 0; i < N; i++)
    {
        cout << i + 1 << " " << D[i] << " " << F[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include "memory.h"
#include <stack>

using namespace std;

bool matrix[100][100];
int n;

int next(int k){
	for(int i = 0; i < n; i++){
		if(matrix[k][i] == true)
			return i + 1;
	}
	return false;
}

int main(){
	int index, temp, num, current, count = 1;
	int start_end[100][2];
	stack<int> back;

	memset(matrix, 0, sizeof(matrix));
	memset(start_end, 0, sizeof(start_end));

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> index >> num;
		while(num--){
			cin >> temp;
			matrix[index-1][temp-1] = true;
		}
	}
	back.push(0);
	current = 0;
	while(true){
		while(!back.empty()){
			int r;
			r = next(current);
			if(start_end[current][0] == 0){
				start_end[current][0] = count;
				count++;
			}
			if(r){
				matrix[current][r-1] = false;
				back.push(current);
				current = r - 1;
			}
			else{
				if(start_end[current][1] == 0){
					start_end[current][1] = count;
					count++;
				}
				current = back.top();
				back.pop();
			}
		
		}
		for(int i = 0; i < n; i++){
			if(start_end[i][0] == 0 || start_end[i][1] == 0){
				back.push(i);
				break;
			}
		}
		if(back.empty())
			break;
	}
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << start_end[i][0] << " " << start_end[i][1] << endl;
	}

}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int N;
int t = 0;
int f[105];
int s[105];
int used[105];


void dfs(int x,vector<vector<int>> &g){
    used[x] = 1;
    t ++;
    f[x] = t;
    for(auto y:g[x]){
        if(!used[y]) dfs(y,g);
    }
    t++;
    s[x] = t;
}

int main(){
    cin>>N;
    FOR(i,0,N) used[i]=0;
    vector<vector<int>> G(N);
    FOR(i,0,N){
        int u,k,v;
        cin >> u >> k; u--;
        FOR(j,0,k){
            cin >> v; v--;
            G[u].push_back(v);
        }
    }
    FOR(i,0,N){
        if(!used[i]) dfs(i,G);
    }
    FOR(i,0,N){
        cout << i+1 << " " << f[i] << " " << s[i] << endl;
    } 
    return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void dfs(const vector<vector<int>>& edges, vector<int>& ds, vector<int>& fs, int u, int& t) {
    if (ds[u] > 0) {
        return;
    }
    ds[u] = ++t;
    for (auto v : edges[u]) {
        dfs(edges, ds, fs, v, t);
    }
    fs[u] = ++t;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> edges(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--;
            edges[u].push_back(v);
        }
        sort(begin(edges[u]), end(edges[u]));
    }
    vector<int> ds(n, -1);
    vector<int> fs(n, -1);
    int t = 0;
    for (int i = 0; i < n; i++) {
        dfs(edges, ds, fs, i, t);
    }
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << ds[i] << " " << fs[i] << endl;
    }
}