Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

C++: #include <stdio.h>
#include <iostream>
using namespace std;

class Adjl{
private:
	int u;
	int k;
	Adjl **next;
protected:
	int d;
	int f;
public:
	Adjl(int u);
	~Adjl(){ if (next != NULL) delete[] next; }
	void setV(int k, Adjl *vk);
	int depthFirstSearch(int time);
	void print();
};

Adjl::Adjl(int u)
{
	this->u = u;
	k = 0;
	next = NULL;
	d = 0;
	f = 0;
}

void Adjl::setV(int k, Adjl *vk)
{
	if (this->k == 0) next = new Adjl*[k];
	next[this->k] = vk;
	(this->k)++;
}

int Adjl::depthFirstSearch(int time)
{
	if (d != 0) return time;
	time++;
	d = time;
	for (int i = 0; i < k; i++) {
		time = next[i]->depthFirstSearch(time);
	}
	time++;
	f = time;
	return time;
}

void Adjl::print()
{
	cout << u << " " << d << " " << f << endl;
}

int main(void)
{
	int n;
	cin >> n;
	
	Adjl **adjl = new Adjl*[n];
	int check[100] = {0};

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		if (check[i] == 0) {
			adjl[i] = new Adjl(u);
			check[i] = 1;
		}
		check[i] = 1;
		for (int j = 0; j < k; j++) {
			int vk;
			cin >> vk;
			if (check[vk - 1] == 0) {
				adjl[vk - 1] = new Adjl(vk);
				check[vk - 1] = 1;
			}
			adjl[i]->setV(k, adjl[vk - 1]);
		}
	}

	int time = 0;
	for (int i = 0; i < n; i++) {
		time = adjl[i]->depthFirstSearch(time);
	}

	for (int i = 0; i < n; i++) {
		adjl[i]->print();
	}

	delete[] adjl;
	return 0;
}

C++: #include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

vector<vector <int>> v;
int color[100],d[100],f[100],t,n;

void dfs_visit(int u)
{
	color[u]=1;
	d[u]=++t;
	int next=-1;
	rep(i,v[u].size())
	{
		if(color[v[u][i]]==0)
		{
			next=v[u][i];
			dfs_visit(next);
		}
	}
	f[u]=++t;
}

void dfs()
{
	rep(i,n)color[i]=0;
	t=0;

	rep(i,n)
	{
		if(color[i]==0)dfs_visit(i);
	}
}

int main()
{
	cin >> n;
	rep(i,n)
	{
		int hoge;cin >> hoge;
		int k;cin >> k;
		v.push_back(vector <int>());
		rep(j,k)
		{
			int fooo; cin >> fooo;
			v[i].push_back(fooo-1);
		}
	}

	dfs();
	rep(i,n)
	{
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
	}
	return 0;
}

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

using namespace std;

#define MAX 110
int num;
int matrix[MAX][MAX];
int dst[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(){
    stack<int> S;
    S.push(0);
    dst[0] = 0;
    while(!S.empty()){
        int cur = S.top();
        S.pop();
        if(dst[cur]==-1 || dst[cur]== 0){
            for(int i=0;i<num;i++){
                if(matrix[cur][i]==1){
                    S.push(i);
                    dst[i] = dst[cur] + 1;
                }
            }
        }
        else if(dst[S.top()]+1 < dst[cur]){
            for(int i=0;i<num;i++){
                if(matrix[cur][i]==1){
                    if(dst[cur] +1 <= dst[i]){
                        S.push(i);
                        dst[i] = dst[cur] + 1;
                    }
                }
            }
        }
    }
    for(int i=0;i<num;i++){
        cout << i+1 << " " <<  dst[i] << endl;
    }
}

int main(){
    input();
    dfs();
}

C++: #include<bits/stdc++.h>
#include<limits.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

#define MAX 200

vector<vector<int>> adj_mat(MAX, vector<int>(MAX, 0));
vector<int> d(MAX, -1); //頂点を訪問したステップを記録
vector<int> f(MAX, -1); //頂点の隣接リストを探索し終えたステップを記録

int n;
int step = 1;

void dfs(int init_node){
    stack<int> s;
    int node = init_node;
    s.push(node);
    d.at(node) = step;

    int next_node = -1;
    while(1){
        step++;

        next_node = -1;
        rep(i, n){
            if(adj_mat.at(node).at(i) == 1 && d.at(i) == -1){
                next_node = i;
                break;
            }
        }

        if(next_node == -1){        //新たなノードがない場合
            s.pop();            //次のノードが存在しないノードをスタックから削除
            if(s.size() == 0){
                f.at(node) = step;
                step++;
                break;
            }
            next_node = s.top();

            f.at(node) = step;   // 新たなノードがないので訪問ずみ
            // cout << "node not found " << node+1 << "    " << next_node+1 << endl;
        }else{                      //新たなノードがある場合
            s.push(next_node);
            d.at(next_node) = step; // 初めて見つけたノードとして記録
            // cout << "node found " << node+1 << " --> " << next_node+1 << endl;
        }
        
        node = next_node;
    }
}

int main(){
    cin >> n;

    // 隣接行列の作成
    rep(i, n){
        int u, k; cin >> u >> k;
        rep(j, k){
            int v; cin >> v;
            adj_mat.at(u-1).at(v-1) = 1;
        }
    }


    rep(i, n){
        if(d.at(i) == -1){
            dfs(i);
        }
    }

    rep(i, n){
        cout << i + 1 << " " << d.at(i) << " " << f.at(i) << endl;
    }


}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> adjlist;
int t=0;
vector<int> d;
vector<int> f;
void input(int n){
	vector<int> f={0,0};
	adjlist.push_back(f);
  for(int i=0;i<n;i++){
    vector<int> list;
    int ln;
    cin>>ln;
    list.push_back(ln);
    cin>>ln;
    list.push_back(ln);
    for(int j=0;j<ln;j++){
      int an;
      cin>>an;
      list.push_back(an);
    }
    adjlist.push_back(list);
  }
}

void depth_search(int id){
	vector<int> list=adjlist[id];
	for(int j=0;j<list[1];j++){
		if(d[list[2+j]]<0){
			d[list[2+j]]=++t;
			depth_search(list[2+j]);
		}
	}
	f[id]=++t;
}
 
void print(int n){
  for(int i=1;i<n+1;i++){
    cout<<i<<' '<<d[i]<<' '<<f[i]<<endl;
  }
}
int main(){
  int n;
  cin>>n;
	d=vector<int> (n+1,-1);
	f=vector<int> (n+1,-1);
  input(n);
	for(int i=1;i<n+1;i++){
		if(f[i]<0){
			d[i]=++t;
			f[i]=t;
			depth_search(i);
		}
	}
  print(n);
  return 0;
}