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<queue>

using namespace std;



int n;
int u[102], k[102],  v[102][102];
int timecount = 0;
int time_keep[102][2];
bool visited[102];
vector<int> vertices[100+5];
bool check(int& remain, int N);


void dfs(int cur){
	visited[cur] = true;
	// cur の訪問時刻を記録
	timecount += 1;
	int e = timecount;
	// 動作確認用表示
	//cerr << "visiting " << cur <<" " << timecount << endl;
	
	//cout << cur + 1 << " " << timecount << " ";
	
	for(auto itr = vertices[cur].begin(); itr!=vertices[cur].end(); itr++){
        if(!visited[*itr]){
            dfs(*itr);
            visited[*itr] = true;
        }
    }
     
	/*
	for(int dst = 0; dst < n; ++dst){
		//timecount1 += 1;
		if(visited[dst] == false){
			dfs(dst);
			visited[dst] = true;
		}
	}
	*/
	
	// cur の訪問終了時刻を記録
	timecount += 1;
	int f = timecount;
	time_keep[cur][0] = e;
	time_keep[cur][1] = f;
	//cout << cur + 1 << " " << e << " " << timecount << endl;
	//cout << timecount << endl;
	// 関数の終わりで親に戻る(青矢印)
}

bool check(int& remain, int N){
    for(int i = 1; i <= N; ++i){
        if(!visited[i]) {
            remain = i;
            //cout << "remain:" << remain  << endl;
            return false;
        }
    }
    return true;
}

int main(){
	cin >> n;
	/*
	for(int i = 0; i < n; ++i){
		cin >> u[i] >> k[i];
		for(int j = 0; j < k[i]; ++j){
			cin >> v[i][j];
			//cout << D[i][j] << endl;
		}
	}
	*/
	for(int i = 0; i < n; ++i){
        int index, itr;
        cin >> index >> itr;
        for(int i = 0; i < itr; ++i) {
            int buff;
            cin >> buff;
            vertices[index].push_back(buff);
        }
    }

	dfs(1);
	int remain;
	//for(int i = 0; i < n; ++i){
	//	dfs(i);
	//}
	while(!check(remain, n)){//未発見のものがないか?
        //cout << "DETECTED" << endl;
        dfs(remain);
    }

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

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

#define N 100

int A[N + 1][N + 1] = {};
int n, u, k, v;
int t = 1; //tは時間
int t1[N + 1] = {}; //発見時刻
int t2[N + 1] = {}; //終了時刻

//sは始点
void dps(int s) {
    t1[s] = t;
    for(int a = 1; a <= n; ++a) A[a][s] = 0;
    for(int i = 1; i <= n; ++i) {
        if(A[s][i] == 1) {
            ++t;
            dps(i);
        }
    }
    ++t;
    t2[s] = t;
    
}

int main(void) {
    cin >> n;
    
    for(int i = 0; i < n; ++i) {
        cin >> u >> k;
        for(int j = 0; j < k; ++j) {
            cin >> v;
            A[u][v] = 1;
        }
    }
    
    for(int i = 1; i <= n; ++i) {
        if(t2[i] == 0) {
            dps(i);
            ++t;
        }
    }
    
    for(int i = 1; i <= n; ++i) {
        cout << i << ' ' << t1[i] << ' ' << t2[i] << endl;
    }
    
    
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstring>
using namespace std;

bool A[110][110],flag[110];
int in[110],out[110];
int n,now=1;
stack<int> S;

void dfs_visit(int u){
	flag[u]=true;
	for(int i=1;i<=n;i++){
		if(A[u][i]==true && flag[i]==false) {
			S.push(i);
			in[i]=now++;
			dfs_visit(i);
		}
	}
	int x=S.top();
	S.pop();
	out[x]=now++;
	return ;
}

void dfs(){
	S.push(1);in[1]=now++;
	while(S.empty()==0){
		int x=S.top();
		dfs_visit(x);
		
	}
	for(int i=1;i<=n;i++) cout<<i<<" "<<in[i]<<" "<<out[i]<<endl;
	return ;
}

int main (){
	int a,b,c;
	cin>>n;
	for(int i=1;i<=n;i++){
		flag[i]=false;
			for(int j=1;j<=n;j++){
				A[i][j]=false;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		for(int j=1;j<=b;j++){
			cin>>c;
			A[a][c]=true;
		}
	}
	dfs();
	return 0;

}

C++: //https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_11_B
//深さ優先探索
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

template< typename T >
struct edge {
	int src, to;
	T cost;
	edge(int _to, T _cost) : src(-1), to(_to), cost(_cost) {}
	edge(int _src, int _to, T _cost) : src(_src), to(_to), cost(_cost) {}
	edge &operator=(const int &x) {
		to = x;
		return *this;
	}
	operator int() const { return to; }
};

template< typename T>
struct node {
	vector<edge<T>> edges;
    ll d=0,f=0;
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< node< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

int main() {
    ll n; cin>>n;
    WeightedGraph<ll> graph(n+1);
    FOR(i,1,n+1){
        ll u, k; cin>>u>>k;
        FOR(j,0,k){
            ll v; cin>>v;
            graph[i].edges.emplace_back(u,v,1);
        }
    }

    ll counter=1;
    function<void(ll)> dfs = [&](ll id){
        auto& node=graph.at(id);
        if (node.d!=0)return; //訪問済
        node.d=counter++;
        for(const auto& e :graph.at(id).edges){
            dfs(e);
        }
        node.f=counter++;
    };

    FOR(i,1,n+1){
        dfs(i);
    }

    FOR(i,1,n+1){
        const auto& node=graph.at(i);
        cout<<i<<" "<<node.d<<" "<<node.f<<endl;
    }

    return 0;
}