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

using namespace std;

int n, M[101][101];
int color[101], count1[101], count2[101], t;

void dfs_visit(int u) {
	int v;
	color[u] = GRAY;
	t++;
	count1[u] = t;
	for (v = 1; v <= n; v++) {
		if (M[u][v] == 0) {
			continue;
		}

		if (color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	t++;
	count2[u] = t;
}

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

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

	for (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;
		for (j = 0; j < k; j++) {
			cin >> v;
			M[u][v] = 1;
		}
	}

	dfs();

	return 0;
}

/*
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0
*/

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

const int MAX_N = 100;
vector<int> G[MAX_N];
int d[MAX_N], f[MAX_N];
bool used[MAX_N];

int stamp;

void dfs(const int v) {
    d[v] = stamp++;
    used[v] = true;
    for(int i = 0; i < (int)G[v].size(); i++) {
        int u = G[v][i];
        if(used[u] == false) dfs(u);
    }
    f[v] = stamp++;
}

int main() {
    int N; cin >> N;
    for(int i = 0; i < N; i++) {
        int u, k; cin >> u >> k; u--;
        while(k--) {
            int v; cin >> v; v--;
            G[u].push_back(v);
        }
        sort(G[u].begin(), G[u].end());
    }

    fill(used, used + N, false);
    stamp = 1;
    dfs(0);

    for(int i = 0; i < N; i++) {
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

struct Node {
	int k, d, f;
	vector<int> v;
};

#define MAX_N 100

Node node[MAX_N + 1];
int _d, _f;

void dfs(int u) {
	if (node[u].d == 0) node[u].d = _d++;
	for (int i = 0; i < node[u].k; ++i)
		dfs(node[u].v[i]);
	if (node[u].f == 0) node[u].f = _f++;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int u;
		cin >> u;
		cin >> node[u].k;
		for (int j = 0; j < node[u].k; ++j) {
			int v;
			cin >> v;
			node[u].v.push_back(v);
		}
		node[u].d = node[u].f = 0;
	}
	_d = 1;
	_f = n + 1;
	dfs(1);
	for (int i = 1; i <= n; ++i)
		cout << i << " " << node[i].d << " " << node[i].f << endl;
	return 0;
}

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

struct Node{
  vector<int> AJ;
  bool visit;
  int d, f;
};

Node G[101];
int t = 0;

void dfs(int idx){
  G[idx].visit = true;
  G[idx].d = ++t;
  for(int i = 0; i < G[idx].AJ.size(); i++){
    if(!G[G[idx].AJ[i]].visit) dfs(G[idx].AJ[i]);
  }
  G[idx].f = ++t;
}

int main(){
  int n, u, k, v;
  cin >> n;
  for(int i = 0 ; i < 101; i++) G[i].visit = false;
  for(int i = 0; i < n; i++){
    cin >> u >> k;
    for(int j = 0; j < k; j++){
      cin >> v;
      G[u].AJ.push_back(v);
    }
  }
  for(int i = 1; i <= n; i++) if(!G[i].visit) dfs(i);
  for(int i = 1; i <= n; i++) cout << i << " " << G[i].d << " " << G[i].f << endl;
  return 0;
}

C++: 
#include<iostream>

using namespace std;

const int MAX = 100;

void search(bool graph[MAX][MAX], int find[], int done[], int n, int u,int& count) {
	count++;
	find[u] = count;
	cout << u << endl;
	for (int i = 0; i < n; i++) {
		if (graph[u][i] && find[i] == 0) {
			search(graph, find, done, n, i, count);
		}
	}
	count++;
	done[u] = count;
}

int main() {
	bool check[MAX] = { false };
	int find[MAX] = { 0 };
	int done[MAX] = { 0 };
	bool graph[MAX][MAX] = { {false} };
	int N;

	cin >> N;
	for (int i = 0; i < N; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int temp;
			cin >> temp;
			graph[u - 1][temp - 1] = true;
		}
	}

	int count = 0;
	for (int i = 0; i < N; i++) {
		if (find[i] == 0) {
			search(graph, find, done, N, 0, count);
		}
	}

	for (int i = 0; i < N; i++) {
		cout << i + 1 << " " << find[i] << " " << done[i] << endl;
	}

	return 0;
}

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

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

void stamp(int id, int t) {
	if (t > 2 * n)
		return;

	if (d[id - 1] == 0) {
		d[id - 1] = t;
		r[t] = id;
		int i = 0;
		while (v[id - 1][i] == 0)
			i++;
		if (i < n && d[i] == 0)
			stamp(i + 1, t + 1);
		else
			stamp(id, t + 1);
	}
	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, t);
				break;
			}
		if (i > n - 1) {
			f[id - 1] = t;
			for(int j = 1; j < d[id - 1]; j++)
				if (r[d[id - 1] - j] != 0) {
					if (f[r[d[id - 1] - j] - 1] == 0)
						stamp(r[d[id - 1] - j], t + 1);
				}

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

int main()
{
	cin >> n;

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

	for(int i = 0; i < 202; i++)
		r[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;
		}
	}

	stamp(1, 1);

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

	return 0;
}