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)
	dfs(&g, &d, &f, 1, 1)

	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>
using namespace std;
void func(int p);
int n;
int box[101][101];
int d[101];
int f[101];
int flg[101];
int t;
int main(void){
	int u,k,v;
	int i,j;
	cin>>n;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			box[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v;
			box[u][v]=1;
		}
	}
	t=0;
	for(i=1;i<=n;i++){
		if(!flg[i]){
			func(i);
		}
	}
	for(i=1;i<=n;i++)	cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}
void func(int p){
	int i;
	t++;
	d[p]=t;
	flg[p]=true;
	for(i=1;i<=n;i++){
		if(box[p][i]==1){
			if(!flg[i]){
				func(i);
			}
		}
	}
	t++;
	f[p]=t;
}

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

int g[101][101], d[101], f[101];

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        int id, k;
        cin>>id>>k;
        g[id][0]=k;
        for(int j=1; j<=k; j++) {
            cin>>g[id][j];
        }
    }
    dfs(1, 0);
    for(int i=1; i<=n; i++) {
        cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
    }
    return 0;
}

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

using namespace std;

int d[10010]={0};//最初に訪問した時刻を入れるタイムスタンプ
int f[10010]={0};//vの隣接リストを調べ終えた時刻のタイムスタンプ

int back[10010]={0};//番号nのもときた街番号をいれる

int g[1001][1001]={{0}};//要素を0で初期化
int timestamp = 1;
int number;
int dfs(int cur){
  timestamp += 1;
  for(int dst = 0; dst < number; dst++){
    if(g[cur][dst]==1 && d[dst]==0){
      d[dst]=timestamp;
      back[dst]=cur;
      dfs(dst);
    }
  }
  // timestamp += 1;
  // cout << "f[cur]" <<f[cur]<<"timestamp"<<timestamp<<"cur"<<cur<<endl;
  // abort();
  if(timestamp > number*2){
    return 0;
  }
  // cout << "f[cur]" <<f[cur]<<"timestamp"<<timestamp<<"cur"<<cur<<endl;
  // abort();
  f[cur]=timestamp;
  dfs(back[cur]);
}
void ans(int n){
  for (int i = 0; i < n; ++i)
  {
    cout << i+1 << " " << d[i] <<" "<< f[i] <<endl;
  }
}

int main(){
  // int g[1001][1001]={{0}};//要素を0で初期化
  int n,a,b,c;
  cin >> n;
  number = n;
  for (int i = 0; i < n; ++i)
  {
    cin >> a >> b ;
    for (int i = 0; i < b; ++i)
    {
      cin >> c;
      g[a-1][c-1]=1;/* code */
    }
  }
  d[0]=1;
  dfs(0);
  for (int i = 0; i < number; ++i)
  {
    if(d[i]==0){
      dfs(i);
    }
  }
  // for (int i = 0; i < number; ++i)
  // {
  //   cout << back[i]<<" ";
  // }

  ans(n);
}

C++: /*
    Problem 24
    https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_11_B
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 102;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int>> G(MAX, vector<int>());
vector<int> d(MAX), f(MAX), deg(MAX), cur(MAX);
int t = 1;
/* function */
void dfs(int st) {
    stack<int> S;
    S.push(st);
    d[st] = t++;
    while (!S.empty()) {
        int from = S.top();
        if (cur[from] >= deg[from]) {
            f[from] = t++;
            S.pop();
            continue;
        }
        int to = G[from][cur[from]++];
        if (d[to] != 0) continue;
        d[to] = t++;
        S.push(to);
    }
}
/* main */
int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k, v;
        cin >> u >> k;
        u--;
        deg[u] = k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            G[u].push_back(v);
        }
    }

    // dfs
    for (int i = 0; i < n; i++) {
        if (d[i] == 0) dfs(i);
    }

    for (int i = 0; i < n; i++)
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << '\n';
}

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

using namespace std;

static const int N = 100; // 1 <= n <= 100
static const int WHITE = 0; // 未訪問は0
static const int GRAY = 1; // 訪問中は1
static const int BLACK = 2; // 訪問完了は2

int n; // 頂点数n
vector<vector<int>> M(N, vector<int>(N,0)); // M[u][v]：uからvに出ているか否か
vector<int> color(N), d(N), f(N); // d(i)：頂点i発見時刻，f(i)：頂点i完了時刻
int tt; // 経過時間tt
vector<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;
}

// 地点rについてスタックを用いた深さ優先探索
void dfs_visit(int r) {
    //初期化
    for ( int i = 0; i < n; i++ ){
        nt[i] = 0;
    }
    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    
    tt++;
    d[r] = tt;
    
    while ( !S.empty() ) {
        int u = S.top();
        int v = next(u);
        if ( v != -1 ) {
            if ( color[v] == WHITE ) {
                color[v] = GRAY;
                tt++;
                d[r] = tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            tt++;
            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] << endl;
    }
}

int 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;
        }
    }
        
        dfs();
        return 0;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define MAX 10000
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
static const int N = 100;
static const int INFTY = 10000000;

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

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  tt++;
  d[u] = tt;
  for( v = 0;v<n;v++){
    if(M[u][v] ==0) continue;
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  tt++;
  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(u = 0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}


int main(){
  int u,v,k,i,j;
  
  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();

}