Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #define scanf_s scanf
#include <string>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <iostream>
using namespace std;

#define MAX 100
//#define MAX_ 1000
struct Graph
{
	int id, k = 0;
	list<int> node;
	int d = 0, f = 0;
};
Graph G[MAX];
int cou = 1;
void Depth(Graph *g)
{
	if (g->k >= 0) {
		if (g->d)
			return; 
		
		g->d = cou;
		++cou;
		for (auto i = g->node.begin(); i != g->node.end(); ++i) {
			Depth(&G[*i]);
		}
		g->f = cou;
		++cou;
		
	}
}

int main(void)
{
	int n, u, xk, v;
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf_s("%d %d", &u, &xk);
		G[u - 1].id = u - 1;
		G[u - 1].k = xk;
		for (int j = 0; j < xk; ++j) {
			scanf_s("%d", &v);
			G[u - 1].node.push_back(v - 1);
		}
	}
	for (int i = 0; i < n; ++i) {
		if (G[i].d == 0 && G[i].f == 0) 
			Depth(&G[i]);
		
	}
	for (int i = 0; i < n; ++i) {
		printf("%d %d %d\n", G[i].id + 1, G[i].d, G[i].f);
	}
}

C++: #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int NIL = -1;

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

//u に隣接するvを番号順に取得
int next(int u){
    for(int v = nt[u]; v < n; v++){
        nt[u] = v + 1;
        if( M[u][v] ) return v; 
    }
    return NIL;
}

void dfs_visit(int r){
    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(S.size() != 0){
        int u = S.top();
        int v = next(u);
        if(v != NIL){
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs_init(){
    for(int i = 0; i < n; i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    //未訪問のuを始点として深さ優先探索
    for(int u = 0; u < n; u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(int i = 0;i < n; i++){
        cout << i + 1 << " " << d[i]  << " " << f[i] << endl;
    }
}

int main(){
    cin >> n;
    int u, k, v;

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

    dfs_init();

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <utility>

using vvb = std::vector<std::vector<bool>>;

struct TimeStamp
{
    int discovered;
    int finished;
};

std::vector<TimeStamp> dfs(const vvb& edges)
{
    using namespace std;

    int time {1};
    const int n = edges.size();
    stack<int> st;
    vector<bool> reached(n);
    vector<TimeStamp> times(n);

    //すべての辺について行う
    for (int i = 0; i < n; ++i)
    {
        if (reached[i])
            continue;

        times[i].discovered = time++;
        st.push(i);
        
        //点iからつながるすべての辺を調べる
        while (!st.empty())
        {
            int top = st.top();
            for(int i = 0; i < n; ++i)
                if (!reached[i] && edges[top][i])
                {
                    reached[i] = true;
                    times[i].discovered = time++;
                    st.push(i);
                    break;
                }

            //その点からの探索候補がなければ前の点に戻る
            if (top == st.top())
            {
                times[top].finished = time++;
                st.pop();
            }
        }
    }

    return times;
}

void solve()
{
    using namespace std;

    int n;
    cin >> n;

    vvb edges(n, vector<bool>(n));

    //読み込み
    for (int i = 0; i < n; ++i)
    {
        int u, k;
        cin >> u >> k;

        for (int j = 0; j < k; ++j)
        {
            int v;
            cin >> v;
            edges[u - 1][v - 1] = true;
        }
    }

    auto times = dfs(edges);

    for (int i = 0; i < n; ++i)
    {
        cout << i + 1 << " " << times[i].discovered << " " << times[i].finished << endl;
    }
}

int main()
{
    solve();
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
int p=0;
int d[200],f[200];
void dfs(const Graph &G, int v) {
    if (!seen[v]) d[v]=p+1;
    seen[v] = true; // v を訪問済にする
    p++;f[v]=p;

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) {
            continue; // next_v が探索済だったらスルー
        }
        dfs(G, next_v); // 再帰的に探索
    }
    p++;f[v]=p;
}

int main() {
   int n;
   cin >> n;
   Graph G(n+1);
   for (int i=0; i<n; i++) {
       int u,k;
       cin >> u >> k;
       for (int j=0; j<k; j++) {
           int v;
           cin >> v;
           G[u].push_back(v);
       }
   }
   seen.assign(n+1,false);
   for (int i=1; i<n+1; i++) {
       if (!seen[i]) {
           dfs(G,i);
       }
   }
   for (int i=1; i<n+1; i++) {
       cout << i << " " << d[i] << " " << f[i] << endl;
   }
}