Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

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

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

using namespace std;
static const int MAX=101;
bool Visited[MAX]; //??\?????????????¢??????????
vector<int> Adjacency[MAX];
int dTime[MAX]; int fTime[MAX]; //?¢??????°??¶??´????¢?????????¶??´
void dfs(int i,int& clock) //??¶????????°?????\???????????¨
{
    clock++;
    Visited[i]=true;
    dTime[i]=clock; //???????????°??¶??´
    for(int j=0;j<Adjacency[i].size();j++)
    {
        if(Visited[Adjacency[i][j]]==true) continue;
        dfs(Adjacency[i][j],clock);
    }
    clock++; //???????????????????¢????
    fTime[i]=clock;
}

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) Visited[i]=false;

    for(int i=1;i<=n;i++)
    {
        int p;cin>>p;
        int num;
        cin>>num;

        for(int j=0;j<num;j++)
        {
            int t;
            cin>>t;
            Adjacency[p].push_back(t);
        }
    }
    int clock=0;
    for(int i=1;i<=n;i++)  //???????????????????????°DFS?£?????????????
    {
        if(Visited[i]==false) dfs(i,clock);
    }
    for(int i=1;i<=n;i++)
        cout<<i<<' '<<dTime[i]<<' '<<fTime[i]<<endl;
}

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

const int MAX = 100;
static int time = 0;
int adj[MAX][MAX];
int discover[MAX];
int finish[MAX];

void visit(int node, int n)
{
  ++time;
  discover[node] = time;

  for (int i = 0; i < n; ++i)
  {
    if (adj[node][i] == 1 && discover[i] == 0)
      visit(i, n);
  }

  ++time;
  finish[node] = time;
}

int main()
{
  std::memset(adj, 0, sizeof(adj));
  std::memset(discover, 0, sizeof(discover));
  std::memset(finish, 0, sizeof(finish));

  int n;
  scanf("%d", &n);

  int u, k, v;
  for (int i = 0; i < n; ++i)
  {
    scanf("%d%d", &u, &k);
    for (int j = 0; j < k; ++j)
    {
      scanf("%d", &v);
      adj[u - 1][v - 1] = 1;
    }
  }

  for (int i = 0; i < n; ++i)
  {
    if (discover[i] == 0)
      visit(i, n);
  }

  for (int i = 0; i < n; ++i)
    printf("%d %d %d\n", i + 1, discover[i], finish[i]);

  return 0;
}