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
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			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
		}
	}
	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++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define VMAX 50
#define EMAX 500
#define DMAX 20
#define TRUE 1
#define FALSE 0
#define NOTUSED 0
#define END -1
#define ROOT -1

// グラフの隣接頂点リスト表現
struct GraphAV{
    int p;  // 頂点数
    int q;  // 辺数
    // int AV[VMAX][DMAX]; 
    vector<vector<int>> AV;  // 隣接頂点リスト
};

GraphAV G;
// int d[VMAX],f[VMAX];
// bool seen[VMAX];
vector<int> d(VMAX);
vector<int> f(VMAX);
vector<bool> seen(VMAX);
int t=1;
void DFS(int v,int& t);

int main(){
    cin>>G.p;

    d.resize(G.p+1);
    f.resize(G.p+1);
    G.AV.resize(G.p+1);
    seen.resize(G.p+1);
    G.AV[0]={NOTUSED};
    d[0]=NOTUSED;
    
    for(int i=1; i<=G.p; i++){
        int u,k;
        cin>>u>>k;
        G.AV[u].resize(k);
        for(int j=0; j<k; j++){
            cin>>G.AV[u][j];
        }
    }

    for(int i=1; i<=G.p; i++){
        if(seen[i]){
            continue;
        }
        DFS(i,t);
    }

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

void DFS(int v,int& t){
    d[v]=t++;

    seen[v]=true;
    // v から行ける各頂点 adj_v について
    for(int adj_v:G.AV[v]){
        if(seen[adj_v]) continue; // adj_v が探索済なら何もしない
        DFS(adj_v,t);  // 再帰的に探索
    }

    f[v]=t++;
}

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

int n, u, k, v;
int d[101], f[101];
pair<int, vector<int>> G[101];

int ti = 1;

void dfs(int id) {
	d[id] = ti ++;

	vector<int>& adj = G[id].second;
	for (int i=0, l=adj.size(); i<l; ++i) {
		if ( ! d[adj[i]]) {
			dfs(adj[i]);
		}
	}
	f[id] = ti ++;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> u >> k;
		G[u].first = u;
		while (k --) {
			cin >> v;
			G[u].second.push_back(v);
		}
	}
	dfs(1);

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

C++: #include <cstdio>
#include <vector>
using namespace std;
int Begin;
int step=1;
int root[105]={0};
typedef struct{
	int id;
	vector<int>next;
	int num;
	int find;
	int finish;
}inf;
void input(int cases,inf table[]){
	for(int i=0;i<cases;i++){
		int id;
		scanf("%d",&id);
		table[id].id=id;
		scanf("%d",&table[id].num);
		for(int i=0;i<table[id].num;i++){
			int next;
			scanf("%d",&next);
			table[id].next.push_back(next);
			root[next]=1;
		}
		table[id].find=-1;
		table[id].finish=-1;
	}
}
void dfs(inf table[],int now){
	if(table[now].num==0){
		table[now].find=step;
		step++;
		table[now].finish=step;
		step++;
		return;
	}else{
		if(table[now].find==-1){
			table[now].find=step;
		}
		step++;
		for(int i=0;i<table[now].num;i++){
			if(table[table[now].next[i]].find==-1){
				dfs(table,table[now].next[i]);				
			}
		}
		table[now].finish=step;
		step++;
	}
}
void find_begin(int cases){
	for(int i=1;i<=cases;i++){
		if(root[i]==0){
			Begin=i;
			break;
		}
	}
}
int main(){
	int cases;
	scanf("%d",&cases);
	inf table[105];
	input(cases,table);
	find_begin(cases);
	dfs(table,Begin);
	for(int i=1;i<=cases;i++){
		printf("%d %d %d\n",i,table[i].find,table[i].finish);
	}
}

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

void DFS(vector<vector<int> >& G,
        vector<pair<int, int> >& rec, int i) {
    if (rec[i].first != -1) return;
    static int t = 1;
    rec[i].first = t++;
    for (int j = 1; j <= G[i].size(); j++) {
        if (G[i][j]) DFS(G, rec, j);
    }
    rec[i].second = t++;
}

int main(){
    int n;
    cin >> n;
    vector<vector<int> > G(n + 1, vector<int>(n + 1, 0));
    for (int i = 1; i <= n; i++) {
        int num, k;
        cin >> num >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            G[i][v] = 1;
        }
    }
    vector<pair<int, int> > record(n + 1, make_pair(-1, -1));
    int t = 1;
    for (int i = 1; i <= n; i++) {
        DFS(G, record, i);
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << record[i].first
                  << " " << record[i].second << endl;
    }

    return 0;
}

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

using namespace std;

#define MAX 110
int num;
int matrix[MAX][MAX];
int dst[MAX];
int counter = 0;
int D[MAX];
int F[MAX];

void input(){
    cin >> num;
    for(int i=0;i<MAX;i++){
        dst[i] = -1;
        for(int j=0;j<MAX;j++){
            matrix[i][j] = 0;
        }
    }
    for(int i=1;i<=num;i++){
        int v; cin >> v;
        int tmp; cin >>tmp;
        for(int j=0;j<tmp;j++){
            int vi; cin >> vi;
            matrix[v-1][vi-1] = 1;
        }
    }
}

void dfs(int cur){
    counter++;
    D[cur] = counter;
    for(int i=0; i< num;i++){
        if(matrix[cur][i] == 1 && D[i]== 0)
            dfs(i);
    }
    F[cur] = counter+1;
    counter++;
    return;
}

int main(){
    input();
    for(int i=0;i<MAX;i++){
        D[i] = 0;
        F[i] = 0;
    }
    dfs(0);
    for(int i=0;i<num;i++){
        cout << i+1 << " " << D[i] << " " << F[i] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()

int d[110];
int f[110];
vector<int> edge[110];
int t=0;
void dfs(int now){
    sort(All(edge[now]));
    if(edge[now].size()==0){
        t++;
        f[now]=t;
    }else{
        for(int i=0;i<edge[now].size();i++){       
            if(d[edge[now][i]]==-1){
                t++;
                d[edge[now][i]]=t;
                dfs(edge[now][i]);
            }
            if(i==edge[now].size()-1){
                t++;
                f[now]=t;
            }
        }
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    fill(d,d+110,-1);
    fill(f,f+110,-1);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            int x;
            cin>>x;
            edge[u].push_back(x);
        }
    }
    for(int i=1;i<=n;i++){
        if(d[i]==-1){
            t++;
            d[i]=t;
            dfs(i);
        }
    }
    for(int i=1;i<=n;i++){
        cout<<i<<' '<<d[i]<<' '<<f[i]<<endl; 
    }

}