Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) doesAllAdjsVisited(vertices []vertex) bool {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return false
		}
	}
	return true
}

func (v *vertex) isFirstVisit() bool {
	return v.firstVisitAt == 0
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func (v *vertex) nextVertex(vertices []vertex) (vertexId, error) {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return vId, nil
		}
	}
	return vertexId(-1), fmt.Errorf("illegal")
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	timestamp = timestamp + 1
	currentVertex := &vertices[currentId-1]
	if currentVertex.isFirstVisit() {
		currentVertex.firstVisitAt = timestamp
	}
	for !currentVertex.doesAllAdjsVisited(vertices) {
		nextVertexId, _ := currentVertex.nextVertex(vertices)
		timestamp = dfs(nextVertexId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

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

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

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	dfs(vertexId(1), 0, vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

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

const int LEN = 100;
const int UNVISITED = 0;
const int FOUND = 1;
const int DONE = 2;

// 再帰関数による深さ優先探索
void dfs_visit(int n, int u, vector<vector<int> >& M, vector<int>& status, vector<int>& d, vector<int>& f, int& tt){
    // 頂点uの訪問状態を「発見」にし,その時刻を記録
    status[u] = FOUND;
    d[u] = ++tt; // ttをインクリメントしてからd[u]に代入

    int v;
    for(v = 0; v < n; v++){
        if(M[u][v] == 0) continue; // 0:隣接していない
        if(status[v] == UNVISITED){
            dfs_visit(n, v, M, status, d, f, tt);
        }
    }

    // 頂点uの訪問状態を「完了」にし,その時刻を記録
    status[u] = DONE;
    f[u] = ++tt; // ttをインクリメントしてからf[u]に代入
}

void dfs(int n, vector<vector<int> >& M){
    vector<int> status(LEN); // status:頂点の訪問状態
    vector<int> d(LEN); // d:頂点の発見時刻
    vector<int> f(LEN); // d:頂点の完了時刻
    int tt; // tt:時刻

    // 初期化 (頂点uの訪問状態を「未訪問」に,また時刻を0に)
    int u;
    for(u = 0; u < n; u++){
        status[u] = UNVISITED;
    }
    tt = 0;

    // 未訪問のuを始点として深さ優先探索
    for(u = 0; u < n; u++){
        if(status[u] == UNVISITED){
            dfs_visit(n, u, M, status, d, f, tt);
        }
    }

    // 結果を出力
    for(u = 0; u < n; u++){
        cout << u + 1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main(){
    int n; // n:頂点数
    vector<vector<int> > M(LEN, vector<int> (LEN)); //  M:頂点同士の隣接を表す行列
    int u, v, k, i, j; // 入力受け取り用

    // 頂点数を受け取り,隣接行列を初期化
    cin >> n;
    int m;
    for(m = 0; m < n; m++){
        for (j = 0; j < n; j++){
            M[m][j] = 0;
        }
    }

    // 頂点番号,出次数,隣接する頂点番号を受け取り,隣接行列に反映
    for(i = 0; i < n; i++){
        cin >> u >> k;
        u--;
        for(j = 0; j < k; j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs(n, M);

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
vector<int> v[105];
int n,step=0,fdepth[105],sdepth[105];
bool visit[105];
void dfs(int node){
    step++;
    fdepth[node]=step;
    int l=v[node].size();
    for(int i=0;i<l;i++)
        if(!visit[v[node][i]]){
            visit[v[node][i]]=1;
            dfs(v[node][i]);
        }
    step++;
    sdepth[node]=step;
}
int allvisit(void){
    for(int i=1;i<=n;i++)
        if(!visit[i])
            return i;
    return 0;
}
int main(){
    ios_base::sync_with_stdio(0);
    //cin.tie(0);
    while(cin>>n){
        memset(fdepth,0,sizeof(fdepth));
        memset(sdepth,0,sizeof(sdepth));
        memset(visit,0,sizeof(visit));
        for(int i=1;i<=n;i++)
            v[i].clear();
        int parent,num,son;
        for(int i=0;i<n;i++){
            cin>>parent>>num;
            while(num--){
                cin>>son;
                v[parent].push_back(son);
            }
        }
        step=0;
        visit[1]=1;
        dfs(1);
        while(allvisit()){
            step=0;
            int node=allvisit();
            visit[node]=1;
            dfs(node);
        }
        for(int i=1;i<=n;i++)
            cout<<i<<' '<<fdepth[i]<<' '<<sdepth[i]<<'\n';
    }
    return 0;
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

#define MAXN 100
int n, timecount = 1;
int ans[MAXN][MAXN];
int d[MAXN], f[MAXN]; // d[i]はdを最初に発見した時刻,f[i]は調べ終わった時刻

int dfs(int p);

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        d[i] = -1;
        f[i] = -1;
    }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            ans[i][j] = 0;
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int tmp;
            cin >> tmp;
            ans[u-1][tmp-1] = 1;
        }
    }
//    for (int i = 0; i < n; i++) {
//        for (int j = 0; j < n; j++) {
//            if (j == n-1) cout << ans[i][j];
//            else cout << ans[i][j] << " ";
//        }
//        cout << endl;
//    }
    dfs(0);
    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
    return 0;
}

int dfs(int p)
{
    int ret = 0, count = 1;
    if (d[p] == -1) d[p] = timecount++;
    for (int i = 0; i < n; i++) {
        if (ans[p][i] == 1 && f[i] == -1) {
            dfs(i);
        }
    }
    if (f[p] == -1) f[p] = timecount;
    timecount++;
    return 0;
}

C++: #include <utility>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int c;
int a[100][100];
int times = 0;
vector<pair<int,int> > v;

vector<int> search(int node)
{
    vector<int> r;
    for(int i = 0;i<c;i++)
    {
        if(a[node][i] == 1)
            r.push_back(i);
    }
    return r;
}

int deep(int node)
{
    if(v[node].first == 0)
    {
        v[node].first = ++times;
        vector<int> r = search(node);
        for(int i = 0;i<r.size();i++)
        {
            deep(r[i]);
            
        }
        v[node].second = ++times;
    }
    else
        return -1;

    return 1;
}

int main() {

    cin >> c;
    for(int i= 0;i<c;i++)
        for(int j = 0;j<c;j++)
            a[i][j] = 0;
    v = vector<pair<int,int> >(c,{0,0});
    for(int i = 0; i<c;i++)
    {
        int rem[2];
        cin >> rem[0] >> rem[1];
        for(int j = 0;j<rem[1];j++)
        {
            int rem11;
            cin >> rem11;
            a[i][rem11-1] = 1;
        }
    }//cin fin
    deep(0);
    
    for(int i = 0; i<c;i++)
    {
        cout << i+1 << " " << v[i].first << " " << v[i].second << endl;
    }
    
    return 0;
}