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++: // ALDS1_11_B.cpp
// Graph I - Depth First Search

#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

struct Vertex
{
    int id;
    vector<int> adjList;
    int d = 0;
    int f = 0;
};

int cnt = 0;

void dfs(vector<Vertex> &V, int n, int i)
{
    if (V[i].d != 0 && V[i].f != 0)
        return;
    int len = V[i].adjList.size();
    V[i].d = ++cnt;

    for (int j = 0; j < len; j++) {
        int next = V[i].adjList[j];
        if (V[next].d == 0) {
            // V[next].d = ++cnt;
            dfs(V, n, next);
            //V[next].f = ++cnt;
        }
    }
    V[i].f = ++cnt;
}

int main()
{
    int n;
    cin >> n;
    vector<Vertex> V(n);
    int id;
    int num;
    for (int i = 0; i < n; i++) {
        cin >> id >> num;
        V[id-1].id = id-1;
        int tmp;
        for (int j = 0; j < num; j++) {
            cin >> tmp;
            V[id-1].adjList.push_back(tmp-1);
        }
    }
    dfs(V, n, 0);
    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", i + 1, V[i].d, V[i].f);
    }
    return 0;
}

C++: #include <stdio.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n,M[N][N]={0};
int color[N]={WHITE},D[N],F[N],tt=0;
void DFS_VISIT(int u){
  int v;
  color[u]=GRAY;
  D[u]=++tt;
  REP(v,n){
    if(M[u][v]==0) continue;
    if(color[v]==WHITE) DFS_VISIT(v);
  }
  color[u]=BLACK;
  F[u]=++tt;
}
void DFS(){
  int u;
  REP(u,n) if(color[u]==WHITE) DFS_VISIT(u);
  REP(u,n) printf("%d %d %d\n",u+1,D[u],F[u]);
}
int main(){
  int u,v,k;
  scanf("%d",&n);
  REP(i,n){
    scanf("%d %d",&u,&k);
    u--;
    REP(j,k){
      scanf("%d",&v);
      M[u][--v];
    }
  }
  DFS();
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> P;

int n, u, k, v, t = 0, G[110][110], used[110];
P p[110];

void dfs(int u) {
    used[u] = 1;
    p[u].first = ++t;
    for (int i = 1; i <= n; i++) {
        if (!G[u][i] || used[i]) continue;
        used[i] = 1;
        dfs(i);
    }
    p[u].second = ++t;
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[u][v] = 1;
        }
    }

    for (int i = 1; i <= n; i++) {
        if (used[i]) continue;
        dfs(i);
    }

    for (int i = 1; i <= n; i++)
        cout << i << " " << p[i].first << " " << p[i].second << endl;

    return 0;
}

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

int r[101][101];
int d[101], f[101], num, visit[100]={0}, p=1;

void dfs(int n){
    if(visit[n]!=1){
        visit[n] = 1;
        d[n] = p++;
        for(int i=1; i<=num; i++)
            if(r[n][i]) dfs(i);
        f[n] = p++;
    }
}

int main(void){
    int u, k, v;
    cin >> num;
    for(int i=1; i<=num; i++){
        cin >> u >> k;
        for(int j=1; j<=k; j++){
            cin >> v;
            r[u][v]=1;
        }
    }
    for(int i=1; i<=num; i++){
        if(visit[i]!=1) dfs(i);
    }
    for(int i=1; i<=num; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
    return 0;
}