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++: #define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

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



using namespace std;




int main() {
	
	int n;
	cin>>n;
	vector<vector<int>>t(n,vector<int>(n));
	for(int i=0;i<n;i++){
		int x,r;cin>>r>>x;
		for(int j=0;j<x;j++){
			int w;cin>>w;w--;t[i].push_back(w);
		}
		sort(t[i].begin(),t[i].end());
	}
	stack<int>S;
	bool F[105]={};
	S.push(0);
	int p=1;
	F[0]=1;
	vector<int>G(n),H(n);
	int g=1;
	G[0]=1;
	while(S.size()){
		g++;
		int v=S.top();
		int a=-1;
		for(int i=0;i<t[v].size();i++){
			if(!F[t[v][i]]){
				a=t[v][i];break;
			}
		}
		if(a==-1){
			H[S.top()]=g;
			S.pop();
		}
		else{
			F[a]=1;
			G[a]=g;
			S.push(a);
		}
	}
	for(int i=0;i<n;i++){
		cout<<i+1<<" "<<G[i]<<" "<<H[i]<<endl;
	}
	

	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <stack>

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

using namespace std;


int adjacencyList[MAX + 1][MAX + 1];
int color[MAX + 1];
int d[MAX + 1];
int f[MAX + 1];
int n;



int minWhiteNode(int v)
{

	for (int i = 1; i <= n; i++) {
		if (color[i] == WHITE && adjacencyList[v][i] == 1 && i != v) {
			return i;
		}
	}
	return 	MAX + 1;
}


void dfs()
{
	stack<int> S;
	int cr;
	int timer = 1;

	S.push(1);
	color[1] = GRAY;
	d[1] = 1;

	while (S.size() > 0) 
	{
		cr = minWhiteNode(S.top());
		timer++;

		if (cr != MAX + 1) {
			S.push(cr);
			color[cr] = GRAY;
			d[cr] = timer;
		}
		else {
			int poped = S.top();
			S.pop();
			color[poped] = BLACK;
			f[poped] = timer;
		}
	}
}

int main(void)
{

	int u;
	int k;
	int v;


	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> u >> k;

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

	}

	dfs();

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

	return 0;
}

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

using namespace std;
int t;

void dfs(vector<vector<bool> >& A, vector<vector<int> >& B, int s, int n){
    for(int i = 0; i < n; i++){
        if(i == 0){
            if(B[s][1] == 0){
                B[s][1] = t;
                t++;
            }
        }
        if(A[s][i] == true){
            A[s][i] = false;
            dfs(A, B, i, n);
        }
        if(i == n-1){
            if(B[s][2] == 0){
                B[s][2] = t;
                t++;
            }
        }
    }
}

int main(void){

    //??£??\??????????????£??\???????????????
    int n, k;

    cin >> n;
    vector<vector<bool> > A(n, vector<bool>(n, false));
    for(int i = 0; i < n; i++){
        cin >> k >> k;
        for(int j = 0; j < k; j++){
            int input;
            cin >> input;
            A[i][input-1] = true;
        }
    }

   

    vector<vector<int> > B(n, vector<int>(3, false));
    for(int i = 0; i < n; i++){
        B[i][0] = i + 1;
    }

    t = 1;
    for(int k = 0; k < n; k++){
        if(B[k][1] == 0) dfs(A, B, k, n);
    }
    

    //??????
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j != 2) cout << B[i][j] << " ";
            else cout << B[i][j];
        }
        cout << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int n;
vector<vector<int>> to, timestamp;

void dfs(int v, int& t) {
    timestamp[v][0] = t++;
    for (int i = 0; i < to[v].size(); ++i) {
        int nv = to[v][i];
        if (timestamp[nv][0] > 0) continue;
        dfs(nv, t);
    }
    timestamp[v][1] = t++;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    to.resize(n);
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        u--;
        rep(j, k) {
            int v;
            cin >> v;
            v--;
            to[u].push_back(v);
        }
    }

    timestamp.resize(n, vector<int>(2, 0));
    int t = 1;
    rep(i, n) {
        if (timestamp[i][0] == 0) dfs(i, t);
    }

    rep(i, n) {
        cout << i+1 << " " << timestamp[i][0] << " " << timestamp[i][1] << endl;
    }
}