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>
#define N 100
#define WHITE 0
#define GRAY  1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u)
{
    int v;
    color[u]=GRAY;
    d[u]=++tt;
    for(v=0;v<n;v++)
    {
        if(M[u][v]==0) continue;
        if(color[v]==WHITE)
            dfs_visit(v);
    }
    color[u]=BLACK;
    f[u]=++tt;
}

void dfs()
{
    int u;
    for(u=0;u<n;u++)
        color[u]=WHITE;
    tt=0;
    for(u=0;u<n;u++)
        if(color[u]==WHITE)
            dfs_visit(u);
    for(u=0;u<n;u++)
        printf("%d %d %d\n",u+1,d[u],f[u]);
}

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

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

struct edge{
    int node;
    edge *next;
}nodes[105];

int n,t[105][2],visit[105],cnt=0;

void dfs_visit(int i){
    t[i][0]=++cnt;
    visit[i]=1;
    edge *e=nodes[i].next;
    if(e!=NULL){
        while(e!=NULL){
            if(!visit[e->node])dfs_visit(e->node);
            e=e->next;
        }
    }
    t[i][1]=++cnt;
}

void dfs(){
    int i;
    for(i=1;i<=n;i++){
        if(visit[i]==0)dfs_visit(i);
    }
}

int main(){
    memset(visit,0,sizeof(visit));
    memset(t,0,sizeof(t));
    cin>>n;
    int i,j;
    for(i=1;i<=n;i++){
        int ii,n_i;
        cin>>ii>>n_i;
        edge* first=&nodes[i];
        for(j=0;j<n_i;j++){
            edge *e=new edge();
            cin>>e->node;
            first->next=e;
            first=e;
        }
    }
    dfs();
//    for(i=0;i<n;i++){
//        edge *e=nodes[i].next;
//        while(e!=NULL){
//            cout<<e->node<<" ";
//            e=e->next;
//        }
//        cout<<endl;
//    }
    for(i=1;i<=n;i++){
        cout<<i<<" "<<t[i][0]<<" "<<t[i][1]<<endl;
    }
    return 0;
}

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

#include <cassert>
#include <climits>

#include <string.h>

#include <vector>
#include <map>
#include <stack>

enum Color
{
    kWhite,
    kGray,
    kBlack,
};

// 頂点数.
int n;

// 各頂点の隣接リスト表現.
std::map< int, std::vector<int> > adj_list;

// 各頂点の訪問状態を管理する.
std::vector<Color> c;

// 初回訪問時.
std::vector<int> d;

// 二回目訪問時.
std::vector<int> f;

void makeAdjListFromInput(int n)
{
    for (int i = 0; i < n; ++i)
    {
        int vertex;
        int degree;

        std::cin >> vertex;
        std::cin >> degree;

        assert(vertex <= n);
        assert(degree <= n);

        std::vector<int> adj_vertexes;

        for (int j = 0; j < degree; ++j)
        {
            int adj;
            std::cin >> adj;
            adj_vertexes.push_back(adj - 1);
        }

        adj_list[vertex - 1] = adj_vertexes;
    }
}

int nextVertex(int current)
{
    std::vector< int > adjs = adj_list[current];
    for (std::vector< int >::iterator it = adjs.begin(); it != adjs.end(); ++it)
    {
        if (c[(*it)] == kWhite)
            return (*it);
    }

    // 見つからなかった.
    return INT_MAX;
}

int firstVertex()
{
    for (int i = 0; i < n; ++i)
    {
        if (c[i] == kWhite)
            return i;
    }

    return INT_MAX;
}

void depthFirstSearch()
{
    int counter = 0;
    std::stack<int> tmp_stack;

    // 諸々初期化.
    for (int i = 0; i < n; ++i)
    {
        c.push_back(kWhite);
        d.push_back(0);
        f.push_back(0);
    }

    while (true)
    {
        int first = firstVertex();
        if (first == INT_MAX)
            break;
        tmp_stack.push(first);
        c[first] = kGray;
        d[first] = ++counter;

        while (! tmp_stack.empty())
        {
            int current = tmp_stack.top();
            int next = nextVertex(current);
            if (next != INT_MAX)
            {
                tmp_stack.push(next);
                c[next] = kGray;
                d[next] = ++counter;
            }
            else
            {
                int pop = tmp_stack.top();
                tmp_stack.pop();
                c[pop] = kBlack;
                f[pop] = ++counter;
            }
        }
    }
}

int main()
{


    std::cin >> n;

    makeAdjListFromInput(n);

    depthFirstSearch();

    for (std::map< int, std::vector<int> >::iterator it = adj_list.begin(); it != adj_list.end(); ++it)
    {
        int v = it->first;
        std::cout << v + 1 << " " << d[v] << " " << f[v] << std::endl;
    }

    return 0;
}