Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

C++: #include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

void dfs(int i, vector<vector<int>> a, vector<int> &d, vector<int> &f) {
	int n = a.size();
	int next = -1;
	REP(j, n) {
		if (d[j] == 0 && a[i][j]) {
			if (next == -1) d[j] = d[i] + 1;
			else d[j] = f[next] + 1;
			next = j;
			dfs(j, a, d, f);
		}
	}
	if (next == -1) f[i] = d[i] + 1;
	else f[i] = f[next] + 1;
}

void dfs_all(vector<vector<int>> a, vector<int> &d, vector<int> &f) {
	int i = 0;
	int n = a.size();
	int end = -1;
	while (1) {
		if (end == -1) d[0] = 1;
		else {
			while (d[i] > 0) i++;
			if (i == n) return;
			d[i] = f[end] + 1;
		}
		end = i;
		dfs(i, a, d, f);
	}
}

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

	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n, 0));
	REP(i, n) {
		int u, k;
		cin >> u >> k;
		u--;
		REP(j, k) {
			int v;
			cin >> v;
			a[u][--v] = 1;
		}
	}
	vector<int> d(n + 1, 0);
	d[0] = 1;
	vector<int> f(n);
	dfs_all(a, d, f);
	
	REP(i, n) {
		cout << i + 1 << " " << d[i] << " " << f[i] << "\n";
	}

	return 0;
}

C++: #include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;
#define MAX 105
vector<int> V[MAX];

int d[MAX], f[MAX];

int t;

void search(int v) {
	if (d[v] != 0)return;
	d[v] = t++;

	for (int i = 0; i < V[v].size(); i++) {
		search(V[v][i]);
	}
	f[v] = t++;
}

int main() {
	t = 1;
	int n;
	cin >> n;
	for (int i = 1; i < n + 1; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int s;
			cin >> s;
			V[u].push_back(s);
		}
	}
	for (int i = 1; i < n + 1; i++) {
		if (d[i] == 0)search(i);
	}
	for (int i = 1; i < n + 1; i++) {
		cout << i << ' ' << d[i] << ' ' << f[i] << endl;
	}

	return 0;
}

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

int m[101][101];
int visit[101];
int d[101];
int f[101];
int n, t;

void dfs(int u){
  visit[u] = 1;
  d[u] = t;
  t++;
  
  for(int i = 0; i < n; ++i){
    if(m[u][i] == 1 && visit[i] == 0){
      dfs(i);
    }
  }

  f[u] = t;
  t++;
}

main()
{
  int u, k, v;
  
  cin >> n;
  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){
    if(visit[i]==0){
      t=1;
      dfs(i);
    }
  }

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

  return (0);
}

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

typedef vector<vector<int>> Graph;

int N;
Graph G;
vector<int> td, tf;
int timestamp;

void dfs(int v){
	td[v] = timestamp++;

	for(int i=0; i<G[v].size(); i++){
		int u = G[v][i];
		if(td[u] == -1){
			dfs(u);
		}
	}

	tf[v] = timestamp++;
}

int main(){
	cin >> N;
	G.resize(N);
	td.resize(N, -1);
	tf.resize(N, -1);

	for(int i=0; i<N; i++){
		int x; cin >> x; x--;
		int k; cin >> k;
		for(int i=0; i<k; i++){
			int y; cin >> y; y--;
			G[x].push_back(y);
		}
	}

	timestamp = 1;
	dfs(0);

	for(int i=0; i<N; i++){
		cout << i+1 << " " << td[i] << " " << tf[i] << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int n;
int d[100] = {0};
int f[100] = {0};
bool m[100][100];
int t = 1;

void dfs(int x) {
  for(int i = 0; i < n; i++) {
    if(d[i] == 0) {
      if(m[x][i] == true) {
        d[i] = t;
        t++;
        dfs(i);
        f[i] = t;
        t++;
      } else if(x == i) {
        d[i] = t;
        t++;
        dfs(i);
        f[i] = t;
        t++;
      }
    }
  }
}

int main() {

  rep(i, n) {
    rep(j, n) {
      m[i][j] = false;
    } 
  }
  m[0][0] = true;
  // m[2][2] = true;

  cin >> n;
  for(int i = 0; i < n; i++) {
    int x, temp;
    cin >> x >> temp;
    for(int j = 0; j < temp; j++) {
      int y;
      cin >> y;
      m[x - 1][y - 1] = true;
    }
  }

  t = 1;
  rep(i, n) {
    // dfs(0);
    dfs(i);
    // if(d[i] == 0) dfs(i);
  }

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

  return 0;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int G[101][101];
int d[101];
int f[101];
bool checked[101];

void explore(int id, int n,int& t)
{
	if (checked[id])
	{
		return;
	}
	checked[id] = true;
	d[id] = t;
	t++;

	for (int i = 1; i <= n; i++)
	{
		if (G[id][i] == 1)
		{
			explore(i, n,t);
		}
	}

	f[id] = t;
	t++;
}

int main()
{
	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int id, k;
		cin >> id >> k;

		for (int i = 0; i < k; i++)
		{
			int v;
			cin >> v;
			G[id][v] = 1;
		}
	}

	int t = 1;
	for (int i = 1; i <= n; i++)
	{
		if (!checked[i])
		{
			explore(i, n, t);
		}
	}

	for (int i = 1; i <= n; i++)
	{
		printf("%d %d %d\n", i, d[i], f[i]);
	}

	return 0;
}