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 <iostream>
using namespace std;

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

int N;
int G[MAX_N][MAX_N];
int color[MAX_N], d[MAX_N], f[MAX_N];
int t;

void bfs_visit(int u) {
    color[u] = GRAY;
    d[u] = ++t;
    for (int i = 0; i < N; i++) {
        if (G[u][i] && color[i] == WHITE) {
            bfs_visit(i);
        }
    }
    color[u] = BLACK;
    f[u] = ++t;
}

void dfs() {
    for (int i = 0; i < N; i++) {
        color[i] = WHITE;
    }
    t = 0;
    for (int i = 0; i < N; i++) {
        if (color[i] == WHITE) {
            bfs_visit(i);
        }
    }
    for (int i = 0; i < N; i++) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

    dfs();
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> v(101);
int dp[101][2] = { 0 };
int n, t = 0;

void dfs(int a) {
	t++;
	if (dp[a][0] == 0) { dp[a][0] = t; }
	for (int i = 0;i < v[a].size();i++) {
		if (dp[v[a][i]][0] == 0) {
			dfs(v[a][i]);
		}
	}
	t++;
	if (dp[a][1] == 0) { dp[a][1] = t; }
}

int main() {
	cin >> n;
	for (int i = 0; i < n;i++) {
		int u,k; cin >> u >> k;
		for (int j = 0; j < k;j++) {
			int x; cin >> x;
			v[u].push_back(x);
		}
	}
	dfs(1);
	for (int i = 1; i <= n;i++) {
		cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << endl;
	}
}

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

#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 visit(int a){
  int b;
  color[a]=GRAY;
  d[a]=++tt;
  for(b=0;b<n;b++){
    if(m[a][b]==0) continue;
    if(color[b]==WHITE) visit(b);
  }
  color[a]=BLACK;
  f[a]=++tt;
}

void dfs(){
  int a;
  for(a=0;a<n;a++) color[a]=WHITE;

  tt=0;

  for(a=0;a<n;a++){
    if(color[a]==WHITE) visit(a);
  }
  for(a=0;a<n;a++) printf("%d %d %d\n",a+1,d[a],f[a]);

}

int main(){
  int u,v,k,i,j;

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

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

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool graph[101][101];
int first_time[101],last_time[101];
int visited[101];
int tt=0;
int v[101][101];
#define white 0
#define gray 1
#define black 2//0回目の訪問、1回目の訪問、2回目の訪問の3種類あるからboolを使わない

void dfs(int v,int n) {
	for (int i = 2; i <= n; ++i) {
		if (graph[v][i] == false)continue;
		if (visited[i] == white) {
			visited[i] = gray;
			++tt;
			first_time[i] = tt;
			dfs(i, n);
		}
	}
	visited[v] = black;
	++tt;
	last_time[v] = tt;

}

int main() {
	int n;
	cin >> n;
	int u, k;
	for (int i = 0; i < n; ++i) {
		cin >> u >> k;
		for (int j = 0; j < k; ++j) {
			cin >> v[u][j + 1];
			graph[u][v[u][j + 1]] = true;
		}
	}
	for (int i = 1; i <= n; ++i) {//1つの始点から全訪問可能とは限らないから
		if (visited[i] == white) {
			visited[i] = gray;
			++tt;
			first_time[i] = tt;
			dfs(i, n);
		}
	}
	for (int i = 1; i <= n; ++i) {
		cout << i << " " << first_time[i] << " " << last_time[i] << endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAX_NODE 101

int begin_times[MAX_NODE];
int end_times[MAX_NODE];
int c_time=0;
queue<int> g[MAX_NODE];

void dfs(int f){
  if(begin_times[f]>0)return;
  c_time++;
  begin_times[f]=c_time;
  while( !g[f].empty() ){
    int to = g[f].front();
    g[f].pop();
    if(end_times[to]>0)continue;
    dfs(to);
  }
  c_time++;
  end_times[f]=c_time;
}

int main(){
  int n;cin>>n;
  rep(i, n){
    int from;
    int count;
    cin>>from>>count;
    rep(j, count){
      int t;cin>>t;
      g[from].push(t);
    }
  }

  rep1(i, n)dfs(i);

  rep1(i, n){
    cout<<i<<' '<<begin_times[i]<<' '<<end_times[i]<<endl;
  }

  return 0;
}