Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

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

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

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

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

#define N_MAX 100

typedef struct _v {
    int k;
    int *v;
    int f;
    int l;
} Vertex;
Vertex Adj[N_MAX];

int t = 1;

void depth_search(int i) {
//    printf(" i %d\n", t);
    if (Adj[i].f == 0) {
        Adj[i].f = t;
//        printf("  Adj[%d] : k = %d f = %d\n", i, Adj[i].k, t);
    }
    else {
        t--;
        return;
    }

    for (int j = 0; j < Adj[i].k; j++) {
        t++;
//        printf("t:%d\n", t);
        depth_search(Adj[i].v[j]);
    }
    t++;
//    printf("t:%d\n", t);
    Adj[i].l = t;
//    printf(" Adj[%d].l = %d\n", i, Adj[i].l);
    return;
}

int main() {
    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        int k;
        cin >> k >> k;
        Adj[i].k = k;
        Adj[i].v = new int[k];
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            Adj[i].v[j] = v - 1;
        }
        Adj[i].f = 0;
        Adj[i].l = 0;
    }

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

    return 0;
}

C++: #include<iostream>
#include<cstdio>
#define Lens 105
using namespace std;
int N;
int A[Lens][Lens];
int S[Lens], E[Lens];
int sum = 0;
char c[Lens];

void dns(int i)
{
	sum++;
	S[i] = sum;
	c[i] = 'g';
	for (int j = 1; j <= N; j++)
	{
		if (A[i][j] == 1 && c[j] == 'w')
			dns(j);
	}
	sum++;
	E[i] = sum;
	c[i] = 'b';
}

int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		int k, n;
		cin >> k >> n;
		c[i] = 'w';
		for (int i = 0; i < n; i++)
		{
			int j;
			cin >> j;
			A[k][j] = 1;
		}
	}
	/*
	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= N; j++)
		{
			if (j > 1)
				cout << ' ';
			cout << A[i][j];
		}
		cout << endl;
	}
	*/
	for (int i = 1; i <= N; i++)
	{
		if (c[i] == 'w')
			dns(i);
	}
	for (int i = 1; i <= N; i++)
	{
		cout << i << ' ' << S[i] << ' ' << E[i] << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B
//
#define N 105
vector<int> nebors[N];//start from 1
int start[N]; // start form 1
int end[N]; //end with 1
int vis_nei[N]; // neighbor
stack<int> s;
void dfs(int k,int d){
	d  = 1;
	s.push(1);
	start[1] = d;
	while(!s.empty()){
		//see the top
		int k = s.top(); // add-- deal with null
		if(vis_nei[k] == 1) {
			int m = s.top(); s.pop();
			end[m] = (++d);
		} else {
			//printf("k:%d\n",k);
			for(int i = 0; i<nebors[k].size(); i++){
				int temp = nebors[k].at(i);
				s.push(temp);
				if(start[temp] == -1){
					start[temp] = (++d);
				}
			}
			vis_nei[k] = 1;
		}
		
	}
	
	//check the adjencit list
	/*for(int i = 0; i<nebors[k].size(); i++){
		int temp = nebors[k].at(i);
		
		
	}*/
	//end[k] = 9-d;
}

int main(){
	int n;
	scanf("%d",&n);
	memset(start,-1,sizeof(start));
	memset(end,-1,sizeof(end));
	memset(vis_nei,-1,sizeof(vis_nei));
	//vis_nei
	for(int i = 1; i<=n; i++){
		int id,num;
		scanf("%d %d",&id, &num);
		for(int j = 0; j<num; j++){
			int temp;
			scanf("%d",&temp);
			nebors[id].push_back(temp);
			//nebors[temp].push_back(id);
		}
	}
	dfs(1,1);
	
	for(int i = 1; i<=n; i++){
		printf("%d %d %d\n",i,start[i],end[i]);
	}
}

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

struct node {
	int num;
	std::vector<int> child;
};

int recurcive(node nodes[],int d[100], int f[100], int n, int count) {
	d[n] = count++;
	for (size_t i = 0; i < nodes[n].child.size(); i++) {
		if (d[nodes[n].child[i]] == 0) {
			count = recurcive(nodes, d, f, nodes[n].child[i], count);
		} else {
			nodes[n].child.erase(std::find(nodes[n].child.begin(), nodes[n].child.end(), nodes[n].child[i]));
		}
	}
	f[n] = count++;

	return count;
}

int main() {
	int node_num;
	node nodes[100];
	std::cin >> node_num;

	for (int i = 0; i < node_num; i++) {
		int n, num;
		std::cin >> n >> num;
		for (int j = 0; j < num; j++) {
			int val;
			std::cin >> val;
			nodes[n - 1].child.push_back(val - 1);
		}
	}

	std::stack<int> st, st2;
	std::vector<int> gone;
	int d[100], f[100];
	int count = 1;

	for (int i = 0; i < 100; i++)
		d[i] = f[i] = 0;

	for (int i = 0; i < node_num; i++) {
		if (d[i] == 0) {
			count = recurcive(nodes, d, f, i, count);
		}
	}

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

C++: #include <cstdio>

typedef struct{
	bool isVisited;
	int degree;
	int start;
	int end;
	int *neighbors;
} node;

int count = 0;

void dfs(node* nodes, int id){
	nodes[id].isVisited = true;
	if (nodes[id].start == 0) nodes[id].start=count;
	for (int i=0; i<nodes[id].degree; i++){
		if (!nodes[nodes[id].neighbors[i]].isVisited){
			count ++;
			dfs(nodes, nodes[id].neighbors[i]);
		}
	}
	count++;
	nodes[id].end = count;
}

int main(){
	int n, d, r, id;
	node *nodes;

	scanf("%d", &n);
	nodes = new node[n+1];
	nodes[0].start=0;
	nodes[0].degree=n;
	nodes[0].neighbors = new int[n];
	for (int i=0;i<n;i++){
		nodes[0].neighbors[i]=i;
	}
	for (int i=1; i<n+1;i++){
		nodes[i].isVisited=false;
		scanf("%d %d", &r, &d);
		nodes[i].degree=d;
		nodes[i].neighbors = new int[d];
		nodes[i].start = 0;
		
		for (int j=0;j<d;j++){
			scanf("%d", &id);
			nodes[i].neighbors[j] = id;
		}
	}

	dfs(nodes, 0);
	for (int i=1; i<n+1;i++){
		printf("%d %d %d\n", i, nodes[i].start, nodes[i].end);
		delete []nodes[i].neighbors;
	}
	delete []nodes;
	return 0;
}