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 <stack>

using namespace std;

static const int N = 100;
static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

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 -1;
}

void dfs_visit (int r) {
    for (int i = 0; i < n; i++) {
        nt[i] = 0;
    }
    
    stack<int> S;
    S.push(r);
    color[r] = Gray;
    d[r] = ++tt;
    
    while(!S.empty()) {
        int u = S.top();
        int v = next(u);
        if (v != -1) {
            if (color[v] == White) {
                color[v] = Gray;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = Black;
            f[u] = ++tt;
        }
    }
    
}

void dfs() {
    for (int i = 0; i < n; i++) {
        color[i] = White;
        nt[i] = 0;
    }
    tt = 0;
    
    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 () {
    int u , k, v;
    cin >> n;
    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++) {
        cin >> u>>k;
        u--;
        for(int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
    
    return 0;
}

C++: #include<iostream>
#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; 

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 -1;
}
//用栈实现的深度优先搜索 
void dfs_visit(int r){
	for(int i = 0;i < n;i++){
		nt[i] = 0;
	}
	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;
	
	while( !S.empty() ){
		int u = S.top();
		int v = next(u);
		if(v != -1){
			if(color[v] == WHITE){
				color[v] = GRAY;
				d[v] = ++tt;
				S.push(v);
			}
		}else{
			S.pop();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}

void dfs(){
	//初始化 
	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(){
	int u,v,k;
	cin >> n;
	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++){
		cin >> u >> k;
		u--;
		for(int j = 0;j < k;j++){
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	
	dfs();
	
	
	
	return 0;
}

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

static int tp = 1;
static int n;

void depth_first(int node, int *start_ts, int *end_ts, int **adj_list) {
    start_ts[node] = tp;
    tp++;
    for (int i = 0; adj_list[node][i] != -1; i++) {
        int dst = adj_list[node][i];
        if (start_ts[dst] != 0) {
            continue;
        }
        depth_first(dst, start_ts, end_ts, adj_list);
    }
    end_ts[node] = tp;
    tp++;
}

int main() {
    std::cin >> n;
    int *adj_list[n];

    int u, k, v;
    for (int i = 0; i < n; i++) {
        std::cin >> u >> k;
        adj_list[u - 1] = new int[k + 1];
        for (int j = 0; j < k; j++) {
            std::cin >> v;
            adj_list[u - 1][j] = v - 1;
        }
        adj_list[u - 1][k] = -1;
    }

    int start_ts[n], end_ts[n];
    memset(start_ts, 0, sizeof(int) * n);
    for (int i = 0; i < n; i++) {
        if (start_ts[i] == 0) {
            depth_first(i, start_ts, end_ts, adj_list);
        }
    }
    for (int i = 0; i < n; i++) {
        std::cout << i + 1 << " " << start_ts[i] << " " << end_ts[i] << std::endl;
    }
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int n = 105;
int cnt = 1;
vector<vector<int>> Graph(n,vector<int>());
vector<bool> visited(n,0);
vector<int> first(n);
vector<int> last(n);

void dfs(int i,int &cnt ){
        //行き
        first.at(i) = cnt;
        cnt ++;
        visited.at(i) = 1;
        
        for(auto p:Graph.at(i)){
                if(visited.at(p)) continue;
                dfs(p,cnt);
        }
        
        //帰り
        last.at(i) = cnt;
        cnt ++;
}

int main(){
        int n;
        cin >>n;
        rep(i,n){
                 int u,k;
                cin >> u >> k;
                --u;
                rep(j,k){
                         int p;
                        cin >> p;
                        --p;
                        Graph.at(u).push_back(p);
                }
        }
        rep(i,n){
                 if(!visited.at(i)) dfs(i,cnt);
        }
        rep(i,n){
                 cout << i+1 <<" ";
                cout << first.at(i) << " ";
                cout << last.at(i) << endl;
        }
        

        return 0;
}