Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

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

void dfs_init();
void dfs(int u);

int n,**List,*deg,*d,*f;
bool **M;
string *color;
int vertex;
int tm;

int main(){
	cin>>n;
	List = new int*[n]; M = new bool*[n]; deg = new int[n]; color = new string[n]; d = new int[n]; f = new int[n];
	for(int i=0;i<n;i++) List[i] = new int[n]; for(int i=0;i<n;i++) M[i] = new bool[n];
	for(int i=0;i<n;i++){
		List[i] = List[i]-1;
		M[i] = M[i]-1;
	}
	List = List-1; M = M-1; deg = deg-1; color = color-1; d = d-1; f = f-1;

	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			M[i][j] = false;
		deg[i] = 0; d[i] = 0; f[i] = 0;
	}
	
	int k;
	for(int i=1;i<=n;i++){
		cin>>vertex>>k;
		for(int j=1;j<=k;j++){
			cin>>List[vertex][j];
			M[vertex][List[vertex][j]] = true;
		}
	}

	dfs_init();

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

	for(int i=1;i<=n;i++){
		delete [] (List[i]+1); delete [] (M[i]+1);
	}
	delete [] (List+1); delete [] (M+1);
	delete [] (deg+1); delete [] (color+1); delete [] (d+1); delete [] (f+1);
	cin.get(); cin.get();
}

void dfs_init(){
	for(int i=1;i<=n;i++) color[i] = "WHITE";
	tm = 0;
	for(int i=1;i<=n;i++){
		if(color[i]=="WHITE"){
			dfs(i);
		}
	}
}

void dfs(int u){
	color[u] = "GRAY";
	d[u] = ++tm;
	for(int v=1;v<=n;v++){
		if(M[u][v]==false) continue;
		if(color[v]=="WHITE"){
			dfs(v);
		}
	}
	color[u] = "BLACK";
	f[u] = ++tm;
}

C++: //aizu
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
using namespace std;

vector <int> v[101];

pair <int, int> af[101];

bitset <101> viz;

int cnt;

void DFS(int nod)
{
    cnt++;
    af[nod].first = cnt;
    viz[nod] = 1;

    for (size_t i = 0; i < v[nod].size(); ++i)
    {
        if (viz[v[nod][i]] == 0)
            DFS(v[nod][i]);
    }
    cnt++;
    af[nod].second = cnt;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n, u, k, ind;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> u >> k;
        for (int j = 1; j <= k; ++j)
        {
            cin >> ind;
            v[u].push_back(ind);
        }
        sort(v[u].begin(), v[u].end());
    }

    for (int i = 1; i <= n; ++i)
        if (viz[i] == 0)
            DFS(i);

    for (int i = 1; i <= n; ++i)
        cout << i << " " << af[i].first << " " << af[i].second << "\n";
    return 0;
}

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

int N;
int a[110][110]={{0}};
int d[110][5]={{0}};
int T=1;

void dfs(int cur);

int main(){
        cin >> N;
        for(int i=0; i<N; i++){
                int v,n;
                cin >> v;
                cin >> n;
                for(int j=0; j<n; j++){
                        int V;
                        cin >> V;
                        a[v-1][V-1]=1;
                }
        }
        for(int i=0; i<N; i++){
                if(!d[i][0])dfs(i+1);
        }
        for(int i=0; i<N; i++){
                cout << i+1 << " ";
                for(int j=0; j<2; j++){
                        cout << d[i][j];
                        if(!j)cout << " ";
                }
        cout << endl;
        }
}


void dfs(int cur){
        d[cur-1][0]=T;
        T++;
        //cerr << "visiting_" << cur << " " << T << endl;
        for(int i=0; i<N; i++){
                if(a[cur-1][i] && !d[i][0])dfs(i+1);
        }
        d[cur-1][1]=T;
        T++;
        if(cur>1)cur--;
}

C++: #include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vvll edge(110, vll(0));
vll d(110, -1), f(110, -1);

void dfs(int n, int &time){
  if(edge.at(n).size() == 0){
    d.at(n) = time;
    time++;
    f.at(n) = time; time++;
    return;
  }
  d.at(n) = time; time++;
  bool flag = true;
  for(int i = 0; i < edge.at(n).size(); i++){
    if(d.at(edge.at(n).at(i)) == -1){
      dfs(edge.at(n).at(i), time);
    }
  }
  f.at(n) = time; time++;
}

int main(){
  int n;
  cin >> n;
  
  for(int i = 0; i < n; i++){
    int u, k;
    cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      ll v;
      cin >> v;
      v--;
      edge.at(u).push_back(v);
    }
  }
  int time = 1;
  for(int i = 0; i < n; i++){
    if(d.at(i) == -1) dfs(i, time);
  }
  
  for(int i = 0; i < n; i++){
    cout << i+1 << ' ' << d.at(i) << ' ' << f.at(i) << endl;
  }

}

C++: #include<cstdio>
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#define _USE_MATH_DEFINES // M_PI????????????????????????
#include<math.h>
#pragma warning(disable:4996)
using namespace std;

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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]==0 ) continue;
		if( 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++){ // ????¨???????u????§??????¨????????±???????????¢?´¢
		if( color[u]==WHITE ) dfs_visit(u);
	}
	for(u=0; u<n; u++){
		cout << u+1 << d[u] << f[u] << "\n";
	}
}

int main(){
	int u, v, k, i, j;
	cin >> n;

	for(i=0; i<n; i++){
		cin >> u >> k;
		u--;
		for(j=0; j<k; j++){
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	dfs();
	return 0;
}