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<stdio.h>
#define N 100
#define WHITE 0 // ????¨??????????????????????????????°
#define GRAY 1 // ??¢?´¢?????????????????????????????°
#define BLACK 2 // ??¢?´¢????????????????????????????????°

int n,/* ????????° */ M[N][N]; /* ??£??\?????? */
int color[N],/* ??????i????¨??????¶??? */ d[N],/* ??????i?????????????¨?????????????????????? */ f[N],/* ??????i?????£??\??????????????????????????????????????? */ tt /* ?????? */;

// ?????°??¢??°???????????±???????????¢?´¢
void dfs_visit(int u){
	int v; // ??¢?´¢?????????????????????
	color[u] = GRAY;
	d[u] = ++tt; // ??????????¨????
	for(v=0;v<n;v++){
		if(M[u][v] == 0) continue; // ??????u????????????v????????????????????¨?????????
		if(color[v] == WHITE){
			dfs_visit(v); // ??????v????¨???????????????¨??????????????°???v??????????????¢?´¢???????§???????
		}
	}
	color[u] = BLACK; // ??¢?´¢??????????????????BLACK?????°????????????
	f[u] = ++tt; // ????????????
}

void dfs(){
	int u;
	// ?????????
	for(u=0;u<n;u++) color[u] = WHITE;
	tt = 0;

	for(u=0;u<n;u++){
		// ????¨???????u????§??????¨????????±???????????¢?´¢
		if(color[u] == WHITE) dfs_visit(u);
	}
	for(u=0;u<n;u++){
		printf("%d %d %d\n",u+1,d[u],f[u]);
	}
}


int main(){
	int u,v,k,i,j; // u:??????????????? k:u???????¬???° v:??£??\?????????????????????

	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++) M[i][j] = 0; // ??£??\??????????????????
	}

	for(i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		u--;
		for(j=0;j<k;j++){
			scanf("%d",&v);
			v--;
			M[u][v] = 1;
		}
	}

	dfs();

	return 0;
}

C++: #include <iostream>

using namespace std;

typedef pair<int, int> p;

int n,u,k,t;
int** v;
p* T;

void bfs(int pos) {
  // if visited
  if (T[pos].first) {
    return;
  }
  // check visit
  T[pos].first = ++t;

  int leng = v[pos][0];
  for (int i = 1; i <= leng; i++) {
    bfs(v[pos][i]);
  }
  T[pos].second = ++t;
}

int main() {
  cin >> n;

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

  T = new p[n+1];
  for (int i = 1; i <= n; i++) {
    T[i] = p(0, 0);
  }

  t = 0;
  for (int i = 1; i <= n; i++) {
    bfs(i);
  }

  for (int i = 1; i <= n; i++) {
    cout << i << " " << T[i].first << " " << T[i].second << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
static const int N=101;
static const int White=0;
static const int Gray=1;
static const int Black=2;

int M[N][N];
int d[N],nt[N],f[N],tt,color[N];
int n;
int next_v(int k){
  for(int i=nt[k];i<=n;i++){
    nt[k]=i+1;
    if(M[k][i]) return i;
  }
  return -1;
}
void dfs_visit(int r){
  stack<int> S;
  S.push(r);
  color[r]=Gray;
  d[r]=++tt;

  while(!S.empty()){
    int u=S.top();
    int v=next_v(u);
    if(v!=-1){
      if(color[v]==White){
        color[v]=Gray;
        d[v]=++tt;
        S.push(v);
      }
    }else{
      S.pop();
      color[u]=Black;
      f[u]=++tt;
    }
  }
}
void dfs(){
  tt=0;
  for(int i=1;i<=n;i++){
    if(color[i]== White)dfs_visit(i);
  }
  for(int i=1;i<=n;i++){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<"\n";
  }
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    int u,k,v;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      M[u][v]=1;
    }
  }
  dfs();
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#define N 2000

using namespace std;
vector<vector<int> > pa;
vector<vector<int> > ch;
int first[N] = {0};
int second[N] = {0};
int timestamp = 0;
void dfs(int x) {
    if (ch[x].empty()) {
        return;
    } else {
        for (int i = 0; i < ch[x].size(); i++) {
            if (first[ch[x][i]] * second[ch[x][i]] == 0) {
                timestamp++;
                first[ch[x][i]] = timestamp;
                dfs(ch[x][i]);
                timestamp++;
                second[ch[x][i]] = timestamp;
            }
        }
        return;
    }
}
int main() {
    int n;
    cin >> n;
    int temp = n;
    pa.clear(); pa.resize(N + 5);
    ch.clear(); ch.resize(N + 5);
    while (temp--) {
        int u, k, v;
        cin >> u >> k;
        for (int i = 0; i < k; i++) {
            cin >> v;
            pa[v].push_back(u);
            ch[u].push_back(v);
        }
    }
    int an = 0;
    for (int i = 1; i <= n; i++) {
        if (pa[i].empty()) {
            an = i;
        } else {
            sort(pa[i].begin(), pa[i].end(), less<int>());
        }
        if (ch[i].empty()) {
            ;
        } else {
            sort(ch[i].begin(), ch[i].end());
        }
    }
    timestamp++;
    first[an] = timestamp;
    dfs(an);
    timestamp++;
    second[an] = timestamp;
    for (int i = 1; i <= n; i++) {
        cout << i << ' ' << first[i] << ' ' << second[i] << '\n';
    }
}

C++: #include <stdio.h>
int d[101],e[101],t=0,n;
bool went[101],graph[101][101];
void dfs(int x){
    if(went[x])return;
    went[x]=true;
    t++;
    d[x]=t;
    for(int i=1;i<=n;i++){if(graph[x][i])dfs(i);}
    t++;
    e[x]=t;
    return;
}
int main(){
    int m,temp,a;
    scanf("%d",&n);
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++)graph[i][j]=false;
        went[i]=false;
    }
    for(int i=0;i<n;i++){
        scanf("%d%d",&a,&m);
        for(int j=0;j<m;j++){
            scanf("%d",&temp);
            graph[a][temp]=true;
        }
    }
    for(int i=1;i<=n;i++)dfs(i);
    for(int i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],e[i]);
}