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 <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
class Graph{
private:
  int node;
  int edge_num;
  vector<vector<int>> edge;  
  vector<int> f;
  vector<int> d;
  int time;
public:
  //***************Constractor****************************
  Graph(int n,vector<int> a,vector<int> b){
    node = n;
    edge_num = a.size();
    time = 1;
    edge.resize(node);
    f.resize(node,0);
    d.resize(node);    
    rep(i,edge_num){
      edge[a[i]].push_back(b[i]);
    }
  }

  //***********************************************
  
  void simple_dfs(int v){
    f[v] = time++;
    for(auto w:edge[v]){
      if(f[w]>0) continue;
      simple_dfs(w);
    }
    d[v] = time++;
  }

  void run_dfs(int s){//check each node can reach goal
    rep(i,node){
      if(f[i]<=0) simple_dfs(i);
    }
  }

  void show(){
    rep(i,node){
      cout << i+1 << " " << f[i] << " " << d[i] << "\n";
    }
  }
};


int main()
{
  int n;
  cin >> n;
  vector<int> a,b;
  rep(i,n){
    int aa;cin >> aa;aa--;
    int m;cin >> m;
    rep(i,m){
      int bb;cin >> bb;bb--;
      a.push_back(aa);
      b.push_back(bb);      
    }
  }

  Graph gp(n,a,b);
  gp.run_dfs(0);
  gp.show();
  
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

vector<set<ll>> v(101);
vector<ll> st(101,-1);
vector<ll> et(101,-1);

ll dfs(ll n,ll time) {
  st[n]=time;
  time++;
  for(auto p:v[n]) {
    if(st[p]<0) {
      time=dfs(p,time);
    }
  }
  et[n]=time;
  return time+1;
}

int main() {
  ll n;
  cin >> n;
  for(ll i=0;i<n;i++) {
    ll f,tn;
    cin >> f >> tn;
    for(ll j=0;j<tn;j++) {
      ll temp;
      cin >> temp;
      v[f].insert(temp);
    }
  }
  for(ll i=1;i<=n;i++) {
    v[0].insert(i);
  }
  dfs(0,0);
  for(ll i=1;i<=n;i++) {
    cout << i << " " << st[i] << " " << et[i] << endl;
  }
}

C++: #include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

vector<vector<int> > G(105);
vector<int> go(105), back(105);
vector<bool> seen(105);
int now=1;

void dfs(int s){

  go[s]   = now++;
  seen[s] = true;

  rep(i,G[s].size()){
    if(seen[G[s][i]]) continue;    
    dfs(G[s][i]);
  }
  
  back[s] = now++;
}

int main(){
  int n;
  cin >> n;
  rep(i,n){
    int u,k;
    cin >> u >> k;
    rep(j,k){
      int x;
      cin >> x;
      G[u].push_back(x);
    }    
  }
  for(int i=1; i<=n; i++) if(!seen[i]) dfs(i);
  rep(i,n){
    cout << i+1 << " " << go[i+1] << " " << back[i+1] << endl;
  }
}

C++: // 深さ優先探索
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 100
// 値の定義
const int EXIST = 1;
const int NO_EXIST = 0;

const int WHITE = 0;// 未訪問
const int GRAY = 1; // 訪問中
const int BLACK = 2;// 訪問完了

// グラフ情報を保持する配列
int ary_graph[MAX_N + 1][MAX_N + 1];

// 各頂点の訪問状態を保持する配列
int color[MAX_N + 1];

// 発見時刻と完了時刻を保持する構造体
typedef struct
{
    int start_time;
    int end_time;
}SearchTime;

SearchTime st_SearchTime[MAX_N];
int search_T = 0;

void depthFirstSearch(int now_vertex, int vertex_num);

int main(void)
{
    int n, u, num, v_num;

    for(int i = 0; i < MAX_N + 1; i++)
    {
        color[i] = WHITE;

        for(int j = 0; j < MAX_N + 1; j++)
        {
            // 配列の初期化
            ary_graph[i][j] = NO_EXIST;
        }
    }

    cin >> n;

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

        for(int j = 0; j < num; j++)
        {
            // 隣接点を記憶する
            cin >> v_num;
            ary_graph[u][v_num] = EXIST;
        }
    }

    // 深さ優先探索を実施
    for(int i = 1; i <= n; i++)
    {
        if( color[i] == WHITE )
        {
            depthFirstSearch(i, n);
        }
    }

    // 結果の表示
    for(int i = 1; i <= n; i++)
    {
        printf("%d %d %d\n", i, st_SearchTime[i].start_time, st_SearchTime[i].end_time);
    }

    return 0;
}

// 深さ優先探索を実施する関数
// now_vertex : 現在の頂点のNo.
// next_vertex : 次の頂点のNo.
// vertex_num : グラフの頂点数
void depthFirstSearch(int now_vertex, int vertex_num)
{
    // 訪問中
    color[now_vertex] = GRAY;

    // 発見時刻の設定
    search_T++;
    st_SearchTime[now_vertex].start_time = search_T;

    for(int i = 1; i <= vertex_num; i++)
    {
        if( color[i] == WHITE
            && ary_graph[now_vertex][i] == EXIST )
        {
            depthFirstSearch(i, vertex_num);
        }
    }

    // 訪問完了
    color[now_vertex] = BLACK;

    // 終了時刻の設定
    search_T++;
    st_SearchTime[now_vertex].end_time = search_T;

    return;
}