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>
using namespace std;
#define int long long
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define N 105
int n,cnt;
int graph[N][N];
int ans1[N],ans2[N];
bool checked[N];
void dfs(int i){
    if(checked[i]) return;
    checked[i] = true;
    ans1[i] = cnt++;
    for(int j = 0; j < n; j++){
        if(graph[i][j]) dfs(j);
    }
    ans2[i] = cnt++;
}

signed main() {
    cin >> n;
    for(int i = 0; i < n; i++){
        int a,b,c;
        cin >> a >> b;
        a--;
        for(int j = 0; j < b; j++){
            cin >> c;
            c--;
            graph[a][c] = 1;
        }
    }

    cnt = 1;
    for(int i = 0; i < n; i++){
        if(!checked[i]) dfs(i);
    }
    for(int i = 0; i < n; i++){
        cout << i + 1 << " " << ans1[i] << " " << ans2[i] << endl;
    }
}

C++: # include <iostream>
# include <vector>
# include <cstdio>
using namespace std;
struct info
{
	int st;
	int ed;
	bool vis = false;
};
int Time = 1;
vector<int> a[105];
info *ans;
void dfs(int i)
{
	ans[i].st = Time++;
	ans[i].vis = true;
	for(int j = 0;j < a[i].size();j++) if(!ans[a[i][j]].vis) dfs(a[i][j]);
	ans[i].ed = Time++;
}
int main(void)
{
	int n,cnt,k,u;
	scanf("%d",&n);
	ans = new info [n+1];
	for(int w = 0;w < n;w++)
	{
		scanf("%d %d",&u,&cnt);
		for(int i = 0;i < cnt;i++)
		{
			scanf("%d",&k);
			a[u].push_back(k);
		}
	}
	for(int i = 1;i <= n;i++) if(!ans[i].vis) dfs(i);
	for(int i = 1;i <= n;i++) printf("%d %d %d\n",i,ans[i].st,ans[i].ed);
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
vector<int> d;
vector<int> f;
vector<bool> used;
vector< vector<int> > v;
int n;
int cnt = 1;

void dfs(int pos){
  d[pos] = cnt; cnt++;
  used[pos] = true;
  for(int i = 0; i < n; i++){
    if(v[pos][i] && !used[i]){
      dfs(i);
    }
  }
  f[pos] = cnt; cnt++;
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n;
  d = f = vector<int>(n, -1);
  used = vector<bool>(n, false);
  v = vector< vector<int> >(n, vector<int>(n, 0));
  for(int i = 0; i < n; i++){
    int u, k; cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      int a; cin >> a;
      a--;
      v[u][a] = 1;
    }
  }
  for(int i = 0; i < n; i++)
    if(!used[i]) dfs(i);
  for(int i = 0; i < n; i++){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }

  return 0;
}

C++: //ノードが持つ情報→子のノードの情報
//ノードが子を持たないときはからのvectorを保持する
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>

using namespace std;

//このようにクラスやストラクトなどで一括で管理してしまえば良い
class Node{//普通の木用のデータ
//ノードはポインタでもっておこう
public:
  ///ノードの番号
  int num;
  //そのノードの親
  Node* p;
  //そのノードの子
  vector<Node*> v;
  //そのノードの発見時刻と完了時刻(これは分けて配列の方がいいかもしれない)
  //int d=0;int f=0;
};

//木じゃないのでrootがあるわけじゃない(重要)

//見つからなかったら-1
//非連結な場合もあるので
int find_next_root(vector<int> va){
  int l= int(va.size());
  for(int i=0;i<l;i++){
    if(va[i]==0){return i;}
  }
  return -1;
}


//Nは始まりのNode
//tはmainで管理しするので
void depth_search(Node& N,int& t,vector<int>& va,vector<int>& vf){
  //呼ばれた前の時点での時間が与えられる
  //子を全部見終わったら、そのノードも足し算してそこで終了する
  t++;
  va[N.num]=t;
  int l=N.v.size();
  for(int i=0;i<l;i++){
    if(va[N.v[i]->num]==0) depth_search(*(N.v[i]),t,va,vf);
  }
  t++;
  vf[N.num]=t;
}


int main(){
  int n;cin>>n;
  vector<Node> V(n);for(int i=0;i<n;i++){V[i].num=i;}
  vector<int> Va(n,0);vector<int> Vf(n,0);

  for(int i=0;i<n;i++){
    int k;cin >> k >> k;
    for(int j=0;j<k;j++){
      int l;cin >>l;l-=1;
      V[l].p=&V[i];
      V[i].v.push_back(&V[l]);
    }
  }
  //初めは一つのグラフだと思ってたけど非連結な場合もある
  int t=0;
  int x=0;
  while(x!=-1){
    depth_search(V[x],t,Va,Vf);
    x=find_next_root(Va);
  }
  for(int i=0;i<n;i++){
    cout << i+1 << " " << Va[i] << " " << Vf[i] << endl;
  }
}

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

void dfs(int cur);
int df[100][2]={};
bool dc[100]={};
bool adj[100][100]={};//初期化を忘れない
int n,u,v,k;
int t = 1;

int main(){
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> u >> k;
    for (int j=0; j<k; j++){
      cin >> v;
      adj[u-1][v-1] = true;
    }
  }
  
 
  dfs(0);
  
  for (int i=0; i<n; i++)
    cout << i+1 << " " << df[i][0] << " " << df[i][1] << endl;

}

void dfs(int cur){
  dc[cur] = true;
  df[cur][0] = t;
  t += 1;
  for (int i=0; i<n; i++){
    if (adj[cur][i] && !dc[i]){
      dfs(i);
    }
  }
  df[cur][1] = t; 
  t += 1;
}