Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type nodeKey int

type DirectedGraphNode struct {
	key       nodeKey
	adjacents []*DirectedGraphNode
	visited   bool
	d         int
	f         int
	parent    *DirectedGraphNode
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(l, r nodeKey) {
	g.nodes[l].adjacents = append(g.nodes[l].adjacents, g.nodes[r])
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for iNodes := 0; iNodes < nNodes; iNodes++ {
		graph.nodes[iNodes] = &DirectedGraphNode{}
		graph.nodes[iNodes].key = nodeKey(iNodes)

		graph.nodes[iNodes].visited = false
		graph.nodes[iNodes].d = infty
		graph.nodes[iNodes].f = infty
		graph.nodes[iNodes].parent = nil
	}
	return &graph
}

type QueueEntry struct {
	node *DirectedGraphNode
	next *QueueEntry
}

type Queue struct {
	head, tail *QueueEntry
}

func (q *Queue) enqueue(node *DirectedGraphNode) {
	entry := QueueEntry{}
	entry.node = node

	if q.tail == nil {
		q.head = &entry
		q.tail = &entry
		return
	}

	q.tail.next = &entry
	q.tail = q.tail.next
}

func (q *Queue) dequeue() *QueueEntry {
	if q.head == nil {
		return nil
	}
	poped := q.head
	q.head = q.head.next
	if q.head == nil {
		q.tail = nil
	}
	return poped
}

func (q *Queue) isEmpty() bool {
	return q.head == nil
}

var time = 0

func fillDistancesByDepthFirstSearch(g *DirectedGraph) {
	for _, u := range g.nodes[1:] {
		if !u.visited {
			dfsVisit(g, u)
		}
	}
}

func dfsVisit(g *DirectedGraph, u *DirectedGraphNode) {
	time++
	u.d = time

	u.visited = true
	for _, v := range u.adjacents {
		if !v.visited {
			v.parent = u
			dfsVisit(g, v)
		}
	}
	time++
	u.f = time
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	g := newDirectedGraph(nNodes + 1)

	for iNode := 0; iNode < nNodes; iNode++ {
		nodeKeyLeft := nodeKey(nextInt())
		nAdj := nextInt()
		for iAdj := 0; iAdj < nAdj; iAdj++ {
			nodeKeyRight := nodeKey(nextInt())
			g.setAdjacency(nodeKeyLeft, nodeKeyRight)
		}
	}

	fillDistancesByDepthFirstSearch(g)

	for iNode := 1; iNode <= nNodes; iNode++ {
		node := g.nodes[iNode]
		fmt.Println(node.key, node.d, node.f)
	}
}

C++: #include <cstdio>

typedef struct Node {
    int id;
    int d;
    int f;
    int count;
} Node;


int count(int id, int now, Node *node, int a[101][100]){
    if(node[id].d == 0) node[id].d = now;
    if(node[id].f != 0) return now - 1;
    for(int i = 0; i < node[id].count; ++i){
        int nextId = a[id][i];
        if(nextId == id) continue;
        now = count(nextId, now + 1, node, a);
    }
    node[id].f = now + 1;
    return node[id].f;
}

int main(){
    int n;
    std::scanf("%d", &n);
    Node node[101];
    int a[101][100];
    for(int i = 1; i <= n; ++i){
        int id;
        std::scanf("%d", &id);
        node[id].id = id;
        std::scanf("%d", &node[id].count);
        for(int j = 0; j < node[id].count; ++j){
            std::scanf("%d", &a[id][j]);
        }
    }
    int now = 0;
    for(int i = 1; i <= n; ++i){
        now = count(i, now + 1, node, a);
    }
    for(int i = 1; i <= n; ++i){
        std::printf("%d %d %d\n", node[i].id, node[i].d, node[i].f);
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

vector<pair<int, int> > ans;
vector<vector<int> > v;
int d = 1;

void dfs(int pos)
{
  ans[pos].first = d++;
  rep(i, v[pos].size())
  {
    int next = v[pos][i];
    if (ans[next].first == -1)
    {
      dfs(next);
    }
  }
  ans[pos].second = d++;
}

int main()
{
  int n;
  cin >> n;
  ans.resize(n);
  v.resize(n);
  rep(i, n)
  {
    ans[i] = make_pair(-1, -1);
    int u, k;
    cin >> u >> k;
    u--;
    v[u].resize(k);
    rep(j, k)
    {
      cin >> v[u][j];
      v[u][j]--;
    }
  }

  rep(i, n)
  {
    if(ans[i].first == -1)
      dfs(i);
  }
  rep(i, n)
  {
    cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <map>
#include <cmath>
#include <stack>

using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N]; //それぞれの頂点でどの値まで調べたか格納（毎回ゼロから探さなくて良くなり速度向上）

//uに隣接するvを順番に取得
int next(int u){
    for(int v = nt[u]; v < n; v++){
        nt[u] = v + 1;
        if(M[u][v]) {
            return v;
        }
    }
    return -1;
}

void dfs_visit(int r){
    for(int i=0;i<n;i++){
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!S.empty()) {
        int u = S.top();
        int v = next(u);
        if (v != -1) {
            if (color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs(){
    //初期化
    for(int i=0;i<n;i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    //未訪問のuを始点として深さ優先探索
    for(int u=0; u<n; u++){
        if(color[u] == WHITE){
            dfs_visit(u); //グラフが連結でない可能性があるため
        }
    }

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

}

int main() {

    int u, k, v;

    cin >> n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            M[i][j] = 0;
        }
    }

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

    dfs();

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int main() {
    int N; cin >> N;
    vector<vector<int>> G(N);
    rep(i, 0, N) {
        int u, k;
        cin >> u >> k;
        u--;
        rep(j, 0, k) {
            int v; cin >> v;
            v--;
            G[u].push_back(v);
        }
    }
    vector<int> d(N), f(N), visited(N);
    int cnt = 0;
    function<void(int)> dfs = [&](int cur) {
        if(visited[cur]) return;
        d[cur] = ++cnt;
        visited[cur] = 1;
        for(auto &to : G[cur]) {
            if(visited[to]) continue;
            dfs(to);
        }
        f[cur] = ++cnt;
    };
    rep(i, 0, N) dfs(i);
    rep(i, 0, N) cout << i + 1 << " " << d[i] << " " << f[i] << '\n';
    return 0;
}

C++: #include <iostream>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;


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]&&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(int i=0;i<n;i++){
			cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
		}
	}



int main(){
	int u,k,v;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			m[i][j]=0;
		}
	}
	for(int i=0;i<n;i++){
		cin>>u>>k;
		u--;
		for(int j=0;j<k;j++){
			cin>>v;
			v--;
			m[u][v]=1;
		}
	}
	
	dfs();
	return 0;
}