Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int time_stamp = 0;
std::vector<int> d;
std::vector<int> f;

void dfs(std::vector<std::vector<int> > &G, std::vector<bool> &is_searched, int i){
	if(is_searched[i]){
		//time++;
		return;
	}
	is_searched[i] = true;
	time_stamp++;
	d[i] = time_stamp;

	for(int j = 0; j < G[i].size(); j++){
		dfs(G, is_searched, G[i][j]);
	}
	time_stamp++;
	f[i] = time_stamp;
	return;
}

int main(int argc, char **argv){
	int n, u, k, v;
	std::vector<std::vector<int> > G;
	std::vector<bool> is_searched;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	G.resize(n);
	is_searched.resize(n, false);
	d.resize(n, 0);
	f.resize(n, 0);
	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> u >> k;
#else
		std::cin >> u >> k;
#endif
		G[u - 1].resize(k);
		for(int j = 0; j < k; j++){
#if INPUT_FROM_FILE
			ifs >> v;
#else
			std::cin >> v;
#endif
			G[u - 1][j] = v - 1;
		}
	}

	for(int i = 0; i < n; i++){
		dfs(G, is_searched, i);
	}

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

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

//次の点へ移動とかする関数
int next_point(int point, int (&a)[100][100], int (&num)[100], int (&back)[100], int time[100][2]){
	int next = a[point][num[point]]-1;
	
	//行先が探索終了しているしている場合、pointを返す
	if(a[next][1] == 0 && time[next][1] != 0){
		a[point][1] -= 1;
		return point;
	}
	
	back[next] = point;
	a[point][1] -= 1;
	return next;
}

int main(void){
	int a[100][100];
	int back[100];				//back[]:現在いる点の始点
	int time[100][2];	//time[i][0]:発見時刻,time[i][1]:探索終了時間
	int m, time_now=1, point=0;	//point:現在探索している点
	int num[100];
	
	cin >> m;
	
	for(int i=0; i<m;i++){
		cin >> a[i][0];
		cin >> a[i][1];
		
		for(int j=2; j<a[i][1]+2; j++){
			cin >> a[i][j];
		}
	}

	//ここまで入力
	//ここから↓
	
	//numを2に初期化
	for(int i=0; i<100; i++){
		num[i] = 2;
		time[i][0] = INT_MAX;
	}
	
	time[0][1] = -1;
	
	time[point][0] = time_now++;
	while(time[0][1] == -1){
		
		//矢印が出ていない場合
		if(a[point][1] == 0){
			time[point][1] = time_now++;	//探索終了時刻を決定
			point = back[point];	//始点へ移動
		}
		
		//矢印が出ている場合
		if(a[point][1] != 0){
			point = next_point(point, a, num, back, time);
			num[back[point]] += 1;
			if(time[point][0] > time_now) time[point][0] = time_now++;	//探索開始時刻を決定
		}
	}
	
	//出力
	for(int i=0; i<m; i++){
		cout << i+1 << " " << time[i][0] << " " << time[i][1] << "\n";
	}
	
	return 0;
}

C++: #include<iostream>
#include<stack>
#include<queue>
using namespace std;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

string col[3] = {"WHITE", "GRAY", "BLACK"};
struct Node{
	int color, d, f;
	queue<int> Q;
};

int main(){
	int n;
	cin >> n;
	Node node[n + 1];
	stack<int> move;
	for(int i = 1; i <= n; i++){
		int u, k, v;
		cin >> u >> k;
		node[u].color = WHITE;
		while(k--){
			cin >> v;
			node[u].Q.push(v);
 		}
	}

	int start = 1;
	int tt = 1, p, next;

	do{
		move.push(start);
		node[start].color = GRAY;
		node[start].d = tt;
		tt++;

		while(!move.empty()){
			p = move.top();
			//cout << "Is at " << p << endl;
			if(node[p].Q.empty()){
				//cout << "Cant move from here!" << endl;
				node[p].color = BLACK;
				node[p].f = tt;
				move.pop();
				tt++;
			} else {
				next = node[p].Q.front();
				if(node[next].color == WHITE){
					//cout << "Moving to " << next << endl;
					move.push(next);
					node[next].color = GRAY;
					node[next].d = tt;
					tt++;
				} else {
					//cout << "Cant move to " << next << endl;
					node[p].Q.pop();
				}
			}
			/*
			for(int i = 1; i <= n; i++)
				cout << i << "'s color is " << col[node[i].color] << endl;
			*/
		}

		start = -1;
		for(int i = 1; i <= n; i++){
			if(node[i].color == WHITE){
				start = i;
				break;
			}
		}
		//cout << "start = " << start << endl;
	} while (start > 0);
	

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

C++: #include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
using ll = long long;
using namespace std;

#define WHITE 1
#define GRAY 2
#define BLACK 3

int now, n, u, k, v, tree[102][102], timeTable[102][2], color[102], timeNow = 1;
stack<int> st;

void dfs(){
    while(1){
        if(st.empty()){
            FOR(l, 1, n + 1){
                cout << l << " " << timeTable[l][0] << " " << timeTable[l][1] << endl;
            }
            break;
        }else{
            now = st.top();
          	if(color[now] == WHITE){
            	timeTable[now][0] = timeNow;
            }
            color[now] = GRAY;
            int cnt = 1;
            while(1){
                if(cnt == n + 1){
                    st.pop();
                    color[now] = BLACK;
                    timeTable[now][1] = timeNow + 1;
                    break;
                }else if(tree[now][cnt] && color[cnt] == WHITE){
                    st.push(cnt);
                    break;
                }
                cnt++;
            }
            timeNow++;
        }
    }
}

int main(){
    cin >> n;
  	REP(i, 102){
    	REP(j, 102){
        	tree[i][j] = 0;
        }
    }
    REP(i, n){
        cin >> u >> k;
        color[i + 1] = WHITE;
        REP(j, k){
            cin >> v;
            tree[u][v] = 1;
        }
    }
    st.push(1);
    dfs();
}

C++: #include<bits/stdc++.h>
using namespace std;
vector<vector<int>> G;
int N;
vector<int> d;
vector<int> f;
int de = 0;
void dfs(int v,int p){
    d[v] = ++de;
    for(auto nv:G[v]){
        if(d[nv]!=-1) continue;
        dfs(nv,v);
    }
    f[v] = ++de;
}
signed main(){
    stack<int> st;
    cin >> N;
    G.resize(N);
    d.assign(N,-1);
    f.assign(N,-1);
    for(int i=0;i<N;i++){
        int id;cin >> id;
        int k;cin >> k;
        for(int j=0;j<k;j++){
            int a;cin >> a;a--;
            G[i].push_back(a);
        }
    }
    /*st.push(0);
    int dep=0;
    while(!st.empty()){
        int now = st.top();
        dep++;
        d[now] = dep;
        st.pop();
        for(int nv:G[now]){
            if(d[nv]!=-1) continue;
            st.push(nv);
        }
    }*/
    for(int i=0;i<N;i++){
        if(d[i]==-1) dfs(i,-1);
    }
    for(int i=0;i<N;i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}