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 <vector>
using namespace std;
vector<int> E[101];
bool visited[101];
int in[101];
int out[101];
int count=0;
int nv(int n)
{
	int i=1;
	for(i=1;i<=n;i++)
	{
		if ( visited[i]==false )
			return i;
	}
	if (i>n) return 0;
}

void bfs(int n)
{
	visited[n]=true;
	in[n]=++count;
	for(vector<int>::iterator it=E[n].begin();it!=E[n].end();++it)
	{
		int now=*it;
		if(visited[now]==false)
			bfs(now);
	}
	out[n]=++count;
}

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int e,n0;
		cin>>e>>n0;
		for(int j=0;j<n0;j++)
		{
			int t;
			cin>>t;
			E[e].push_back(t);
		}
		visited[i]=false;
		in[i]=out[i]=0;
	}

	int now=nv(n);
	while(now!=0)
	{
		bfs(now);
		now=nv(n);
	}


/*	for(int i=1;i<=n;i++)
	{
		for(vector<int>::iterator it=E[i].begin();it!=E[i].end();++it)
			cout<<*it<<" ";
		cout<<endl;
	}
*/
	for(int i=1;i<=n;i++)
		cout<<i<<" "<<in[i]<<" "<<out[i]<<endl;
	return 0;

	

}

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

int n, t;
int v[100][100];
int d[100], f[100], r[100];

void stamp(int id) {
	if (d[id - 1] == 0) {
		d[id - 1] = t;
		t++;
		int i = 0;
		while (v[id - 1][i] == 0)
			i++;
		if (i < n && d[i] == 0)
			stamp(i + 1);
		else
			stamp(id);
	}
	else if (f[id - 1] == 0) {
		int i;
		for(i = 0; i < n; i++)
			if (v[id - 1][i] == 1 && d[i] == 0)
				stamp(i + 1);
		if (i > n - 1 && f[id - 1] == 0) {
			f[id - 1] = t;
			t++;
			int j1, ct = 0;
			for (int j = n - 1; j > -1; j--)
				if (v[j][id - 1] == 1 && f[j] == 0 && d[j] != 0) {
					j1 = j;
					ct++;
				}
			if (ct == 1)
				stamp(j1 + 1);
			else {
				for (int j = 1; j < n; j++)
					if (d[j] == d[id - 1] - 1)
						stamp(j + 1);
			}

			int k = 0;
			while (d[k] != 0)
				k++;
			if (k < n)
				stamp(k + 1);
		}
	}
	else	
		return;
}

int main()
{
	cin >> n;

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

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			v[i][j] = 0;

	for (int i = 0; i < n; i++) {
		int u, k, s;

		cin >> u >> k;

		for (int j = 0; j < k; j++) {
			cin >> s;
			v[u - 1][s - 1] = 1;
		}
	}

	t = 1;
	stamp(1);

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

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

const int MAX=200;

int state[MAX],d[MAX],f[MAX],N;
vector<int> T[MAX];
stack<int> S;

void DFS(){
    int time=0,count=0;
    while(count!=N){
        for(int j=0;j<N;j++){
            if(state[j]==0){
                S.push(j);
                state[j]=1;
                time++;
                d[j]=time;
                break;
            }
        }
    while(S.size()){
        int a=S.top();
        bool flag=true;
        for(int i=0;i<T[a].size();i++){
            if(state[T[a][i]]==0){
                S.push(T[a][i]);
                state[T[a][i]]=1;
                time++;
                d[T[a][i]]=time;
                flag=false;
                break;
            }
        }
            if(flag){
                time++;
                state[a]=2;
                count++;
                f[a]=time;
                S.pop();
            }
            
        }
    }
    for(int i=0;i<N;i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

int main(){
   
    int u,k,a;cin>>N;
    
    for(int i=0;i<N;i++){
        state[i]=0;
        d[i]=0;
        f[i]=0;
    }
    
    for(int i=0;i<N;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>a;
            a--;
            T[u].push_back(a);
        }
    }
    DFS();
}

C++: #include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<stack>
#define MAX 105
#define WT 0
#define GR 1
#define BK 2

using namespace std;

int M[MAX][MAX];
int cr[MAX], d[MAX], f[MAX];
int t;
stack<int> ck;
void dfs_init(int n)
{
    t = 1;

    for(int i = 1; i <= n; i++)
        cr[i] = WT;

    return;
}
void dfs(int k,int n)
{
    if(cr[k] == WT)
    {
        cr[k] = GR;
        d[k] = t;
        t++;
        ck.push(k);

        for(int i = 1; i <= n; i++)
        {
            if(M[k][i] == 1 && cr[i] == WT)
                dfs(i,n);
            else if(i == n)
            {
                dfs(ck.top(),n);ck.pop();
            }
        }
    }
    else if(cr[k] == GR)
    {
        ck.pop();
        cr[k] = BK;
        f[k] = t;
        t++;

        if(!ck.empty())
            dfs(ck.top(),n);
        else
            return;
    }
}
int main()
{
    int i, j, n, p, q, tmp;

//Set the matrix: M[n][n]
    for(i = 0; i < MAX; i++)
        for(j = 0; j < MAX; j++)
            M[i][j] = 0;

    scanf("%d", &n);

    for(i = 0; i < n; i++)
    {
        scanf("%d%d", &p, &q);

        for(j = 0; j < q; j++)
        {
            scanf("%d", &tmp);
            M[p][tmp] = 1;
        }
    }

    //DFS:d[v] and f[v] for start and end
    dfs_init(n);
    dfs(1,n);

    for(i = 1; i <= n; i++)
        printf("%d %d %d\n", i, d[i], f[i]);

    return 0;
}