Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	g := graph{}
	g.ee = make([]Edges, n)
	g.visited = make([]bool, n)
	g.found = make([]int, n)
	g.leave = make([]int, n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner) - 1
		k := getNextInt(scanner)
		for j := 0; j < k; j++ {
			v := getNextInt(scanner) - 1
			g.ee[u] = append(g.ee[u], Edge{
				to: v,
				id: u,
			})
		}
	}
	for i := 0; i < n; i++ {
		sort.Sort(g.ee[i])
	}
	for i := 0; i < n; i++ {
		if g.visited[i] {
			continue
		}
		g.dfs(i)
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", i+1, g.found[i], g.leave[i]))
	}
}

// Edge ...
type Edge struct {
	to, id int
}

type Edges []Edge

func (a Edges) Len() int           { return len(a) }
func (a Edges) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Edges) Less(i, j int) bool { return a[i].id < a[j].id }

type graph struct {
	ee           []Edges
	t            int
	n            int
	visited      []bool
	found, leave []int
}

func (g *graph) dfs(i int) {
	g.visited[i] = true
	g.t++
	g.found[i] = g.t
	for _, e := range g.ee[i] {
		if g.visited[e.to] {
			continue
		}
		g.dfs(e.to)
	}
	g.t++
	g.leave[i] = g.t
}

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

using namespace std;

typedef struct node_{
    public:
        queue<int> next;//次の添字(0始まりに変換している)
        int visited;
        int k;//出次数
        int u;//頂点番号
        int d;//発見時刻
        int f;//完了時刻
        node_(){};
}* node;

vector<node> readGraph(int n){
    vector<node> graph;
    for(int i = 0; i < n; i++){
        int u;
        int k;
        scanf("%d %d", &u, &k);
        node nd = new node_;
        nd -> k = k;
        nd -> u = u;
        nd -> visited = 0;
        for(int j = 0; j < k; j++){
            int v;
            scanf("%d", &v);
            v--;//0始まりに
            nd -> next.push(v);
        }
        graph.push_back(nd);
    }
    return graph;
}

void depthFirstSearch(vector<node> graph, int n){
    stack<int> st;
    int cnt = 0;//時刻
    for(int i = 0; i < n; i++){
        if(graph[i] -> visited == 1){
            
        }else{
            st.push(i);
            cnt++;
            graph[i] -> d = cnt;
            graph[i] -> visited = 1;
            while(st.empty() != 1){
                node nd = graph[st.top()];
                if(nd -> next.empty() == 1){
                    cnt++;
                    nd -> f = cnt;
                    st.pop();
                }else{
                    node nx = graph[nd -> next.front()];
                    if(nx -> visited == 1){
                        nd -> next.pop();
                    }else{
                        cnt++;
                        nx -> d = cnt;
                        nx -> visited = 1;
                        st.push(nd -> next.front());
                        nd -> next.pop();
                    }
                }
                /*
                if(graph[st.top()] -> next.empty() == 1){//訪れた点のnextがない//nextがemptyだとvisitedにならない
                    cnt++;
                    graph[st.top()] -> f = cnt;
                    st.pop();
                }else if(graph[graph[st.top()] -> next.front()] -> visited == 1){
                    graph[st.top()] -> next.pop();
                }else{
                    cnt++;
                    graph[graph[st.top()] -> next.front()] -> d = cnt;
                    graph[graph[st.top()] -> next.front()] -> visited = 1;
                    st.push(graph[st.top()] -> next.front());
                    graph[st.top()] -> next.pop();
                }
                */
            }
        }
    }
}

void printTestGraph(vector<node> graph, int n){
    for(int i = 0; i < n; i++){
        node nd = graph[i];
        printf("node[%d] u = %d k = %d\n", i, nd -> u, nd -> k);
        for(int j = 0; j < nd -> k; j++){
            printf("%d ", nd -> next.front());
            nd -> next.pop();
        }
        printf("\n");
    }
}

void printResult(vector<node> graph, int n){
    for(int i = 0; i < n; i++){
        node nd = graph[i];
        printf("%d %d %d\n", nd -> u, nd -> d, nd -> f);
    }
}

int main(){
    //printf("start\n");
    int n;
    scanf("%d", &n);
    vector<node> graph = readGraph(n);
    //printf("readGraph() end\n");
    //printTestGraph(graph, n);//ここまでうまくいってる
    depthFirstSearch(graph, n);
    //printf("depthFirstSearch() end\n");
    printResult(graph, n);
    return 0;
}

C++: #include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v=0; v<n; v++){
        if(M[u][v] == 0) continue;
        if(color[v] == WHITE) {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;
    for(u=0; u<n; u++) color[u] = WHITE;
    tt = 0;
    
    for(u=0; u<n; u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(u=0; u<n; u++){
        printf("%d %d %d\n", u+1, d[u], f[u]);
    }
}

int main(){
    int u, v, k, i, j;
    
    scanf("%d", &n);
    for(i=0; i<n; i++){
        for(j=0; j<n; j++) M[i][j] = 0;
    }
    
    for(i=0; i<n; i++){
        scanf("%d %d", &u, &k);
        u--;
        for(j=0; j<k; j++){
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    dfs();
    
    return 0;
}

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

int M[101][101], sta[101], en[101], n;
stack<int>S;

void dfs()
{
	int id, op;
	bool have;
	id = op = 1;

	while (true)
	{ 
		if (sta[id] == 0)          
		{
			S.push(id);
			sta[id] = op++;
		}

		have = false;
		
		for (int pid = 1; pid <= n; pid++)
		{
			if (M[id][pid] == 1 && sta[pid] == 0)     
			{
				id = pid;
				have = true;
				break;
			}
		}

		if (!have)
		{
			S.pop();
			en[id] = op++;

			if (!S.empty())
				id = S.top();
			else
			{
				for (int i = 1; i <= n; i++)
				{
					if (sta[i] == 0)
					{
						id = i;
						break;
					}		
				}			
			}
		}

		if (op > 2 * n)
			break;
	}
}

int main()
{
	int id, pid, k;

	memset(M, 0, sizeof(M));
	memset(sta, 0, sizeof(sta));
	memset(en, 0, sizeof(en));

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> id >> k;

		for (int j = 1; j <= k; j++)
		{
			cin >> pid;
			M[id][pid] = 1;
		}
	}

	dfs();

	for (int i = 1; i <= n; i++)
		cout << i << " " << sta[i] << " " << en[i] << endl;

	return 0;
}