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 <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

vector<pair<int, int> > ans;
vector<vector<int> > v;
int d = 1;

void dfs(int pos)
{
  ans[pos].first = d++;
  rep(i, v[pos].size())
  {
    int next = v[pos][i];
    if (ans[next].first == -1)
    {
      dfs(next);
    }
  }
  ans[pos].second = d++;
}

int main()
{
  int n;
  cin >> n;
  ans.resize(n);
  v.resize(n);
  rep(i, n)
  {
    ans[i] = make_pair(-1, -1);
    int u, k;
    cin >> u >> k;
    u--;
    v[u].resize(k);
    rep(j, k)
    {
      cin >> v[u][j];
      v[u][j]--;
    }
  }

  rep(i, n)
  {
    if(ans[i].first == -1)
      dfs(i);
  }
  rep(i, n)
  {
    cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <map>
#include <cmath>
#include <stack>

using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N]; //それぞれの頂点でどの値まで調べたか格納（毎回ゼロから探さなくて良くなり速度向上）

//uに隣接するvを順番に取得
int next(int u){
    for(int v = nt[u]; v < n; v++){
        nt[u] = v + 1;
        if(M[u][v]) {
            return v;
        }
    }
    return -1;
}

void dfs_visit(int r){
    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) {
            if (color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs(){
    //初期化
    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] <<"\n";
    }

}

int main() {

    int u, k, v;

    cin >> n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            M[i][j] = 0;
        }
    }

    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;
        }
    }

    dfs();

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int main() {
    int N; cin >> N;
    vector<vector<int>> G(N);
    rep(i, 0, N) {
        int u, k;
        cin >> u >> k;
        u--;
        rep(j, 0, k) {
            int v; cin >> v;
            v--;
            G[u].push_back(v);
        }
    }
    vector<int> d(N), f(N), visited(N);
    int cnt = 0;
    function<void(int)> dfs = [&](int cur) {
        if(visited[cur]) return;
        d[cur] = ++cnt;
        visited[cur] = 1;
        for(auto &to : G[cur]) {
            if(visited[to]) continue;
            dfs(to);
        }
        f[cur] = ++cnt;
    };
    rep(i, 0, N) dfs(i);
    rep(i, 0, N) cout << i + 1 << " " << d[i] << " " << f[i] << '\n';
    return 0;
}

C++: #include <iostream>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;


int n,m[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
	int v;
	color[u]=GRAY;
	d[u] = ++tt;
	for(v=0;v<n;v++){
		if(m[u][v]&&color[v]==WHITE)
		dfs_visit(v);
	}
	color[u] = 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++){
		if(color[u]==WHITE){
			dfs_visit(u);
		}
		}
			for(int i=0;i<n;i++){
			cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
		}
	}



int main(){
	int u,k,v;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			m[i][j]=0;
		}
	}
	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;
		}
	}
	
	dfs();
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

ll cnt = 0;
vector<pair<ll, ll>> ans;
vector<bool> visited;
void f(ll node, vector<vector<ll>> &graph) {
  if (visited[node]) return;
  visited[node] = true;

  ll found = ++cnt;
  for(ll nxt: graph[node]) {
    f(nxt, graph);
  }
  ll solve = ++cnt;
  ans[node] = {found, solve};
}

int main() {
  ll input(n);
  vector<vector<ll>> graph(n);
  ans = vector<pair<ll, ll>>(n);
  visited = vector<bool>(n);
  REP(i, n) {
    ll input(u, k);
    REP(j, k) {
      ll input(v);
      graph[u - 1].push_back(v - 1);
    }
  }

  REP(i, n) f(i, graph);
  REP(i, n) {
    cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
  }
}