Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：Depth First Search
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_11_B
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----
static const ll N_MAX = 110;

// グローバル変数（入力）
ll n, t, A[N_MAX][N_MAX], d[N_MAX], f[N_MAX], state[N_MAX];

// 入力
void input() { cin >> n; }

// 深さ優先探索
void dfs(ll u) {
  d[u] = ++t;
  state[u] = 1; // 発見
  rep(i, n) {
    ll v = i + 1;
    if (A[u][v] == 1 && state[v] == 0) { // 辺が存在かつ未発見なら
      dfs(v);
    }
  }
  f[u] = ++t;
  state[u] = 2; // 完了
}

void solve() {
  // 隣接リストを隣接行列に変換して二次元配列Aに格納
  rep(i, n) {
    ll v, k;
    cin >> v >> k;
    rep(j, k) {
      ll v2;
      cin >> v2;
      A[v][v2] = 1;
    }
  }

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

  // 出力
  rep(i, n) { cout << i + 1 << " " << d[i + 1] << " " << f[i + 1] << endl; }
}

int main() {
  input();
  solve();
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

vi G[200];
int cnt=1;
int s[200],f[200];
void dfs(int v){
    s[v]=cnt++;
    rep(k,SZ(G[v])){
        if(s[G[v][k]]) continue;
        dfs(G[v][k]);
    }
    f[v]=cnt++;
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    rep(i,N){
        int a,n; cin >> a >> n;
        a--;
        rep(j,n){
            int b; cin >> b;
            b--;
            G[a].eb(b);
        }
    }
    rep(i,N){
        if(!s[i]) dfs(i);
    }
    rep(i,N){
        cout << i+1 << " " << s[i] << " " << f[i] << "\n";
    }
}

C++: #include <iostream>
#include <vector>

using namespace std;

int n, t;
vector<int> G[101];
int d[101], f[101];
bool used[101];

void dfs(int v) {
	used[v] = true;
	d[v] = ++t;
	for (int i = 0; i < G[v].size(); ++i) {
		int e = G[v][i];
		if (!used[e]) dfs(e);
	}
	f[v] = ++t;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int u, k; cin >> u >> k;
		while (k--) {
			int v; cin >> v;
			G[u].push_back(v);
		}
	}

	for (int i = 1; i <= n; ++i)
		if(!used[i]) dfs(i);

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

	return 0;
}

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

int t = 1;
int n;
int a[105][105];

vector<int> d;
vector<int> f;
vector<int> g;
vector<int> color;

void visit(int u){
  color[u] = GRAY;
  d[u] = t++;

  for(int i = 0; i < n; i++){
    if(a[u][i] == 0) continue;
    if(color[i] == WHITE) visit(i);
  }

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

void dfs(){
  for(int i = 0; i < n; i++) color[i] = WHITE;

  for(int i = 0; i < n; i++){
    if(color[i] == WHITE) visit(i);
  }
}

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

  d.resize(n+5);
  f.resize(n+5);
  g.resize(n+5);
  color.resize(n+5);

  for(int i = 0; i < n; i++){
    cin >> u >> k;
    u--;

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

  dfs();

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

  return 0;

}

C++: #include<bits/stdc++.h>
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 nt[N], color[N];
int d[N], f[N];
int tt;

int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (m[u][v] == 1)
			return v;
	}
	return -1;
}

void dfs(int u) {
	for (int i = 0; i < n; i++)
		nt[i] = 0;
	stack<int> s;
	s.push(u);
	color[u] = gray;
	d[u] = ++tt;
	while (!s.empty()) {
		int u = s.top();
		int v = next(u);
		if (v != -1) {
			if (color[v] == white) {
				s.push(v);
				color[v] = gray;
				d[v] = ++tt;
			}
		} else {
			s.pop();
			color[u] = black;
			f[u] = ++tt;
		}
	}
}

void dfs_init() {
	tt = 0;
	for (int i = 0; i < n; i++)
		color[i] = white;
	
	for (int i = 0; i < n; i++) {
		if (color[i] == white)
			dfs(i);
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}

int main() {
	int k, u, 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_init();
	return 0;
}

C++: #include<iostream>
#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];

int next(int u)
{
    for (int v = nt[u]; v < n; v++)
    {
        nt[u] = v + 1;
        if (M[u][v] > 0) 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;

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

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