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>
using namespace std;
int a[120][120],b[120][2],u,k,v,n,cou=1;
void dfs(int i){
  b[i][0]=cou;
  cou++;
  for(int j=1;j<=n;j++){
    if(a[i][j]==1&&b[j][0]==0)dfs(j);
  }
  b[i][1]=cou;
  cou++;
}

int main(){
  cin>>n;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      a[i][j]=0;
      b[i][0]=0;
      b[i][1]=0;
    }
  }
  for(int i=1;i<=n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      a[u][v]=1;
    }
  }
  dfs(1);
  for(int i=1;i<=n;i++){
    cout<<i<<" "<<b[i][0]<<" "<<b[i][1]<<endl;;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1 << 21;
const ll MOD = 1e9 + 7;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n; // 頂点の数
int M[N][N]; // グラフ
int color[N]; // 訪問状況
int d[N]; // 発見時刻
int f[N]; // 完了時刻
int tt; // 現在時刻
int nt[N]; // 隣接しているノード

// uに隣接するvを番号順に取得
int next(int u)
{
    for (int v = nt[u]; v < n; ++v) {
        nt[u] = v + 1; // M[u][v]があるときnt[u]=v+1となる
        if (M[u][v]) { // u->vに道があればvを返す
            return v;
        }
    }
    return -1;
}

// スタックを用いた深さ優先探索
void dfs_visit(int r)
{
    // ntを初期化
    for (int i = 0; i < n; ++i) {
        nt[i] = 0;
    }
    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while (!S.empty()) {
        int u = S.top();
        int v = next(u);
        if (v != -1) { // rから伸びるパスが会ったら
            if (color[v] == WHITE) { // まだ訪問したことがないノードのとき
                color[v] = GRAY; // ノードを訪問済みにする
                d[v] = ++tt; // 訪問済みのノードの時間を更新
                S.push(v); // 訪問済みのノードを格納する
            }
        } else { // rから伸びるパスがない時
            S.pop(); // スタックから取り出す
            color[u] = BLACK; // スタックの上にあるノードを訪問完了
            f[u] = ++tt; // 終了時間を更新
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int u, k, v;
    cin >> n;
    memset(M, 0, sizeof(M));

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

    // 初期化
    for (int i = 0; i < n; ++i) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    // 未訪問のuを始点として深さ優先探索
    for (int u = 0; u < n; ++u) {
        if (color[u] == WHITE) {
            dfs_visit(u);
        }
    }

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

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<utility>
using namespace std;
vector<int> l[101];
int matrix[100][100];
pair<int,int> t[101];
int tim=0;
void dfs(int cur)
{
    tim+=1;
    t[cur].first=tim;
    cerr<<"visiting "<<cur<<' '<<tim<<endl;
    
    for(int i=0;i<l[cur].size();i++)
    {
        if(matrix[cur-1][l[cur][i]-1]==1)
        {
            dfs(l[cur][i]);
        }
    }
    
    tim+=1;
    t[cur].second=tim;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            int tmp;
            cin>>tmp;
            l[u].push_back(tmp);
        }
    }
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            matrix[i][j]=0;
        }
    }
    for(int i=1;i<n+1;i++)
    {
        for(int j=0;j<l[i].size();j++)
        {
            matrix[i-1][l[i][j]-1]=1;
        }
    }
    
    dfs(1);
    
    for(int i=1;i<n+1;i++)
    {
        cout<<i<<" "<<t[i].first<<" "<<t[i].second<<endl;
    }
}

C++: #include<stdio.h>
#define N 100
#define Black 2
#define White 0
#define Gray 1

int n,A[N][N];
int IRO[N],a[N],b[N],tt ;

void DFS_HOUMON(int u)
{
  int i;
  IRO[u] = Gray;
  a[u] = ++tt;
  for(i=0;i<n;i++)
    {
      if(A[u][i] == 0) continue;
      if(IRO[i] == White)
	{
	  DFS_HOUMON(i);
	}
    }
  IRO[u] = Black;
  b[u] = ++tt;
}

void DFS()
{
  int u;
  for(u=0;u<n;u++)IRO[u] = White;
  tt = 0;

  for(u=0;u<n;u++)
    {
      if(IRO[u] == White)DFS_HOUMON(u);
    }

  for(u=0;u<n;u++)
    {
      printf("%d %d %d\n",u+1,a[u],b[u]);
    }
}
   

int main()
{
  int u,p,q,ii,j;

  scanf("%d",&n);

  for(ii=0;ii<n;ii++)
    {
      for(j=0;j<n;j++) A[ii][j] = 0;
    }
  for(ii=0;ii<n;ii++)
    {
      scanf("%d %d" ,&u,&q);
      u--;
      for(j=0;j<q;j++)
	{
	  scanf("%d",&p);
	  p--;
	  A[u][p] = 1;
	}
    }

  DFS();

  return 0;
}