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 <algorithm>
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

//---------------------------------------------------------------
// ------ graph ------ //
using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
struct Graph {
    vector<Edges> adj;
    Graph(int n) : adj(n) { }
    int size() { return adj.size(); }
    Edges operator [] (int v) { return adj[v]; }
    void add_edge(int a, int b, Weight w = 1) { // graph
        adj[a].emplace_back(a, b, w);
        adj[b].emplace_back(b, a, w);
    }
    void add_arc(int a, int b, Weight w = 1) {  // digraph
        adj[a].emplace_back(a, b, w);
    }
};
using Array = vector<Weight>;
using Matrix = vector<Array>;
//---------------------------------------------------------------

using vi = vector<int>;
void dfs(int src, Matrix &M, vi &time_s, vi &time_t, int &time) {
    int n = M.size();
    time_s[src] = time++;
    for (int dst = 0; dst < n; dst++) {
        if (M[src][dst] && time_s[dst] < 0) {
            dfs(dst, M, time_s, time_t, time);
        }
    }
    time_t[src] = time++;
}

int main() {
    int n; cin >> n;
    Matrix M(n, Array(n, 0));
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        while (k--) {
            int v; cin >> v; M[u - 1][v - 1]++;
        }
    }
    vector<int> time_s(n, -1), time_t(n, -1);
    int time = 0;
    for (int i = 0; i < n; i++) if (time_s[i] < 0) {
        dfs(i, M, time_s, time_t, time);
    }
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << time_s[i] + 1 << " " << time_t[i] + 1 << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int graph[101][101]={};
int d[101]={};
int f[101]={};
int n,v,k,time1 = 0,sw[101] = {};


void dfs1(int u){

  sw[u] = 1;
  d[u] = ++time1;

  for(int i = 1; i <= n; i++){
    if( graph[u][i] == 1 && sw[i] == 0 ){
     dfs1(i);
    }

  }
    f[u] = ++time1;
}


int main(){
  int u;
  cin >> n ;
  //グラフをつくる
  for(int i = 0; i < n; i++){
    cin >> u >> k ;
    for(int j = 0; j < k ; j++){
      cin >> v;
      graph[u][v] = 1;
    }
  }

  dfs1(1);

  for(int i = 1; i <= n; i++ ){
    cout << i << ' ' <<  d[i]<< ' ' << f[i] << endl;

  }
}

C++: #include<stdio.h>
int tu[1000][1000];
int a[10000];
int d[10000];
int f[10000];
int shijian,n;
void sou(int u){
     a[u]=2;
     d[u]=++shijian;
     for(int i=0;i<n;i++){
        if(tu[u][i]==0) continue;
        if(a[i]==1) {
            sou(i);
        }
     }
     a[u]=3;
     f[u]=++shijian;
}
void shensou(){
     for(int u=0;u<n;u++){
        a[u]=1;
     }
     shijian=0;
     for(int u=0;u<n;u++){
        if(a[u]==1)sou(u);
     }
     for(int u=0;u<n;u++){
         printf("%d %d %d\n",u+1,d[u],f[u]);
     }
}


int main(){
   int v;
   int m;
   int x;
   scanf("%d",&n);
   for(int i=0;i<n;i++){
        scanf("%d%d",&v,&m);
        v--;
        for(int j=0;j<m;j++){
            scanf("%d",&x);
            x--;
            tu[v][x]=1;
        }
   }
   shensou();
return 0;
}

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

using namespace std;

int main(){
    stack<int> st;
    int n;
    cin >> n;
    int d[n] = {};
    int f[n] = {};
    int vnum[n][2] = {};
    bool vflag[n] = {};
    int tmp2;
    int num;
    vector<vector<int>> vertex;
    vector<int> tmp;
    for(int i=0;i<n;i++){
        cin >> num;
        cin >> num;
        vnum[i][0] = num;
        for(int j=0;j<num;j++){
            cin >> tmp2;
            tmp.push_back(tmp2);
        }
        vertex.push_back(tmp);
        tmp.clear();
    }
    int cnt = 1;
    bool check;
    int s;
    st.push(0);
    do{
        s = st.top();

        if(((vnum[s][0]==0) && d[s]==0) || (s==vertex[s][vnum[s][1]]-1)){
            vflag[s] = true;
            d[s] = cnt++;
            f[s] = cnt++;
            st.pop();
        }else if(vnum[s][0]==vnum[s][1]){
            vflag[s] = true;
            f[s] = cnt++;
            st.pop();
        }else if((vflag[vertex[s][vnum[s][1]]-1]) && (d[s]==0)){
            if(vnum[s][0]-vnum[s][1]==1){
                vflag[s] = true;
                d[s] = cnt++;
                f[s] = cnt++;
                st.pop();
            }else{
                vnum[s][1]++;
            }
        }else if(vflag[vertex[s][vnum[s][1]]-1]){
            vflag[s] = true;
            f[s] = cnt++;
            st.pop();
        }else if(vflag[s]){
            st.push(vertex[s][vnum[s][1]++] - 1);
        }else{
            if(d[s]==0){
                d[s] = cnt++;
            }
            st.push(vertex[s][vnum[s][1]++] - 1);
            if(vnum[s][0]==vnum[s][1]){
                vflag[s] = true;
            }
            if(vflag[vertex[s][vnum[s][1]]-1]){
                f[s] = cnt++;
                st.pop();
            }
        }
        check = !st.empty();
        if(!check){
            for(int i=0;i<n;i++){
                if(vflag[i]==false){
                    check = true;
                    st.push(i);
                    break;
                }
            }
        }
    }while(check);

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