Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits.h>
using namespace std;
bool flag[101];
int d[101];
int f[101];
vector<int> v[101];
int t;
void dfs(int node){
	flag[node] = true;
	d[node] = t;
	bool finished = true;
	if (finished && f[node] == 0) f[node] = t;
	for (int i = 0; i < v[node].size(); ++i){
		int tmp = v[node][i];
		if (!flag[tmp]){
			++t;
			dfs(tmp);
			++t;
		}
	}
	f[node] = t;
}
int main(){
	int n; scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		int u, k; scanf("%d %d",&u,&k);
		int tmp;
		for (int j = 0; j < k; ++j){
			scanf("%d", &tmp);
			v[u].push_back(tmp);
		}
	}
	v[0].push_back(1);
	dfs(0);
	++t;
	for (int i = 1; i <= n; ++i){
		if (d[i] == 0) dfs(i);
	}
	
	for (int i = 1; i <= n; ++i){
		cout << i << ' ' << d[i] << ' ' << f[i]+1 << '\n';
	}
}

C++: #include <stdio.h>
 #define GRAY 1
#define WHITE 0
#define BLACK 2
 
int de[101], f[101], col[101];
int A[101][101];
int n, time;
 
void visit(int u) {
  int v;
   col[u] = GRAY;
   de[u] = ++time;
 
  for (v = 1; v <= n; v++) {
    if (col[v] == WHITE && A[u][v] == 1) visit(v);
  }
  col[u] = BLACK;
  f[u] = ++time;
}
 
void dfs() {
  int u;
  for (u = 1; u <= n; u++) {
    col[u] = WHITE;
  }
  time = 0;
  for (u = 1; u <= n; u++) {
    if (col[u] == WHITE) {
      visit(u);
    }
  }
}
 
int main() {
  int i, j, u, k, v;
 
  scanf("%d\n", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &u, &k);
    for (j = 1; j <= k; j++) {
      scanf("%d ", &v);
      A[u][v] = 1;
    }
  }
 
  dfs();
  for (i = 1; i <= n; i++) {
    printf("%d %d %d\n", i, de[i], f[i]);
  }
 
 
  return 0;
}

C++: #include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

vector<bool> seen;
vector<int> first_order;
vector<int> last_order;

void dfs(const vector<vector<int>> &G, int v, int& count)
{
first_order[v]=count+1;
count++;
seen[v]=true;
for(auto next_v : G[v])
{
if(seen[next_v])continue;
dfs(G, next_v, count);
}
last_order[v]=count+1;
count++;
}

int main()
{
int n,u,k;scanf("%d", &n);
vector<vector<int>> G(n);
for(int i=0;i<n;i++)
{
scanf("%d %d", &u, &k);
for(int i=0;i<k;i++){int v;scanf("%d", &v);G[u-1].push_back(v-1);}
}
seen.assign(n,false);
first_order.resize(n);
last_order.resize(n);
int count=0;
for(int i=0;i<n;i++){if(seen[i])continue;dfs(G, i, count);}
for(int i=0;i<n;i++){printf("%d %d %d\n", i+1, first_order[i], last_order[i]);}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int matrix[110][110];
int d[110];
int f[110];
int n;
int elapsed = 1;

void visit(int v) {
  d[v] = elapsed++;

  FOR(i, 1, n + 1) {
    if (matrix[v][i] && d[i] < 0 ) {
      visit(i);
    }
  }
  f[v] = elapsed++;
}

int main() {
  REP(x, 110) {
    REP(y, 110) {
      matrix[x][y] = 0;
    }
    d[x] = -1;
    f[x] = -1;
  }

  // int n;
  cin >> n;

  REP(_, n) {
    int v, num;
    cin >> v >> num;

    REP(i, num) {
      int cv;
      cin >> cv;
      matrix[v][cv] = 1;
    }
  }


  visit(1);

  FOR(v, 1, n + 1) {
    cout << v << " " << d[v] << " " << f[v] << endl;
  }


  return 0;
}

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

class node {
public:
	int d = -1, f = -1, k, v[100];
};

int cnt = 1;
node V[101];

void Serch(int u) {
	V[u].d = cnt; cnt++;

	for (int i = 0; i < V[u].k; i++) {
		if (V[V[u].v[i]].d < 0) {
			Serch(V[u].v[i]);
		}
	}

	V[u].f = cnt; cnt++;
}

int main() {
	int n, u;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u; cin >> V[u].k;
		for (int j = 0; j < V[u].k; j++) {
			cin >> V[u].v[j];
		}
	}

	for (int i = 1; i <= n; i++) {
		if (V[i].d < 0) Serch(i);
	}

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

C++: #include<iostream>
using namespace std;
const int MAX = 100;
int n, G[MAX + 1][MAX + 1] = { 0 };
int tt, d[MAX + 1], f[MAX + 1];
bool book[MAX + 1] = { false };
void dfs_visit(int u)
{
	for (int v = 1; v <= n; v++)
		if (G[u][v] && !book[v])
		{
			d[v] = ++tt;
			book[v] = true;
			dfs_visit(v);
		}
	f[u] = ++tt;
}
void dfs()
{
	for(int i=1;i<=n;i++)
		if (!book[i])
		{
			d[i] = ++tt;
			book[i] = true;
			dfs_visit(i);
		}
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int u, d;
		cin >> u >> d;
		for (int j = 1; j <= d; j++)
		{
			int v;
			cin >> v;
			G[u][v] = 1;
		}
	}
	dfs();
	for (int i = 1; i <= n; i++)
		cout << i << " " << d[i] <<" "<<f[i] << endl;
}