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 <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;
const int INF = 1e18;

struct edge
{
    int to;
    int cost;
};
using Graph = vector<vector<edge>>;

#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
Graph G;

int seen[110];
int discover[110];
int finish[110];
int stamp = 0;

void dfs(int cur)
{
    discover[cur] = stamp++;

    seen[cur] = BLACK;
    for (auto ne : G[cur])
    {
        int v = ne.to;
        int vc = ne.cost;
        if (seen[v] == BLACK)
            continue;
        dfs(v);
    }

    finish[cur] = stamp++;
}

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    G.resize(n + 1);

    for (int i = 0; i <= n; i++)
    {
        if (i == 0)
        {
            for (int j = 1; j <= n; j++)
            {
                G[0].push_back((edge){j, 1});
            }
        }
        else
        {
            int u, k;
            cin >> u >> k;
            for (int j = 0; j < k; j++)
            {
                int v;
                cin >> v;
                G[u].push_back((edge){v, 1});
            }
        }
    }

    for (int i = 0; i < 110; i++)
    {
        seen[i] = WHITE;
        discover[i] = INF;
        finish[i] = INF;
    }

    dfs(0);

    for (int i = 1; i <= n; i++)
    {
        cout << i << " " << discover[i] << " " << finish[i] << endl;
    }
}

signed main()
{
    solve();
    return 0;
}

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

int n, t;
int v[100][100];
int d[100], f[100];

void stamp(int id) {
//	if (t > 2 * n)
//		return;
	
	if (d[id - 1] == 0) {
		d[id - 1] = t;
		t++;
		int i = 0;
		while (v[id - 1][i] == 0)
			i++;
		if (i < n && d[i] == 0)
			stamp(i + 1);
		else
			stamp(id);
	}
	else if (f[id - 1] == 0) {
		int i;
		for(i = n - 1; i > -1; i--)
			if (v[id - 1][i] == 1 && d[i] == 0)
				stamp(i + 1);
		if (i < 0 && f[id - 1] == 0) {
			f[id - 1] = t;
			t++;
			for (i = n - 1; i > -1; i--)
				if (v[i][id - 1] == 1 && f[i] == 0)
					stamp(i + 1);
		}
	}
	else
		return;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		d[i] = 0;
		f[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;
		}
	}

	t = 1;
	stamp(1);

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

	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>

using namespace std;

int common_time=1,n;

int table[101][101],time_table[101][2];

void func(int node){
	if(time_table[node][0] == 0){
		time_table[node][0] = common_time++;
	}else{
		return;
	}
	for(int i=1;i<=n;i++){
		if(table[node][i] == 1){
			func(i);
		}
	}
	time_table[node][1] = common_time++;
}

int main(){
	int row,num,col;
	scanf("%d",&n);

	for(int i=1;i<=n;i++){
		for(int k=1;k<=n;k++){
			table[i][k]=0;
		}
		time_table[i][0]=0;
		time_table[i][1]=0;
	}

	for(int i=1;i<=n;i++){
		scanf("%d %d",&row,&num);
		for(int k=1;k<=num;k++){
			scanf("%d",&col);
			table[row][col]=1;
		}
	}

	for(int i=1;i<=n;i++){
		func(i);
	}

	for(int i=1;i<=n;i++){
		printf("%d %d %d\n",i,time_table[i][0],time_table[i][1]);
	}

    return 0;
}

C++: #include <iostream>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

using namespace std;

int n, t = 0;
int color[MAX+1];
int m[MAX+1][MAX+1];
int d[MAX+1], f[MAX+1];

void visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++t;
    for(v = 1; v <= n; v++){
        if(m[u][v] == 0) continue;
        if(color[v] == WHITE) visit(v);
    }
    color[u] = BLACK;
    f[u] = ++t;
}

void dfs(){
    int u, i;
    for(u = 1; u <= n; u++) color[u] = WHITE;
    for(u = 1; u <= n; u++){
        if(color[u] == WHITE) visit(u);
    }
}

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

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

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

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

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

using namespace std;

vector<int> adja[101];
int d[101], f[101], cnt;

void dfs(int u) {
    d[u] = ++cnt;
    for (auto v : adja[u]) {
        if (d[v] > 0)
            continue;
        dfs(v);
    }
    f[u] = ++cnt;
}

int main() {
    int n, k, u;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        adja[u].resize(k);
        for (int j = 0; j < k; ++j) {
            cin >> adja[u][j];
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (d[i] == 0)
            dfs(i);
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}