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 <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
#define NIL -1

stack<int>S;
int A[1000][1000]={};
string color[1000]={"WHITE"};
int d[1000]={},f[1000]={},nt[1000];
int n,tt=0;

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


void dfs(int u){
    S.push(u);
    color[u]="GRAY";
    d[u] = ++tt;

    int v;
    while(!S.empty()){
        u=S.top();
        v=next(u);
        if(v != NIL){
            if(color[v] == "WHITE"){
                color[v] = "GRAY";
                S.push(v);
                d[v] = ++tt;
            }
        }
        else{
            color[u] = "BLACK";
            S.pop();
            f[u] = ++tt;
        }
        
    }

}

    void dfs_init(){
        REP(i,n){
            color[i]="WHITE";
            nt[i]=0;
        }
    }

int main() 
{
    cin >> n;

    int p,k;
    rep(i,n){
        cin >> p >> k;
        int q;
            rep(j,k){
                cin >> q;
                A[p][q] = 1;
            }
    }

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

    REP(i,n){
        cout << i <<" " << d[i] << " " << f[i] << endl;
    }

}

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

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";
	time = 0;
	for(int i=1;i<=n;i++){
		if(color[i]=="WHITE"){
			dfs(i);
		}
	}
}

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

C++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int m[100][100];
int n;
int used[100];
int d[100], f[100];
int ti = 0;

void dfs(int u)
{
    used[u] = 1;
    d[u] = ++ti;

    rep(i, n)
    {
        if (m[u][i] == 0)
            continue;
        if (used[i] == 0)
            dfs(i);
    }
    f[u] = ++ti;
}

int main()
{
    cin >> n;
    rep(i, n) used[i] = 0;
    rep(i, n) rep(j, n) m[i][j] = 0;

    rep(i, n)
    {
        int u, k;
        cin >> u >> k;
        --u;
        rep(j, k)
        {
            int v;
            cin >> v;
            m[u][--v] = 1;
        }
    }

    rep(i, n) if (!used[i]) dfs(i);

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

    return 0;
}

C++: #include<iostream>
using namespace std;
int N,t=0;
int d[101][101],Ts[101],Te[101];
bool visit[101];
void graph(){
    int u,k,a;
    for(int i=1;i<=N;++i){
        cin>>u>>k;
        for(int j=0;j<k;++j){
            cin>>a;
            d[u][a]=1;
        }
        visit[i]=true;
    }
}
void dfs(int cur){
    t+=1;
    Ts[cur]=t;
    visit[cur]=false;
    for(int i=1;i<=N;++i){
        if(d[cur][i]==1&&visit[i]){
            dfs(i);
        }
    }
    t+=1;
    Te[cur]=t;
}
int main(){
    cin>>N;
    graph();
    for(int i=1;i<=N;++i){
        if(visit[i]) {
            dfs(i);
        }
    }
    for(int i=1;i<=N;++i){
        cout<<i<<" "<<Ts[i]<<" "<<Te[i]<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

vector< vector<int> > list;
vector<int> d, f;
int t;

void dfs(int v) {
  if (d[v] != 0) {
    return;
  }
  
  d[v] = t++;
  for (int i = 0; i < list[v].size(); i++) {
    int visit = list[v][i];
    dfs(visit);
  }
  f[v] = t++;
}
  

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

  t = 1;
  
  int n;
  cin >> n;

  list.resize(n+1);
  d.resize(n+1, 0);
  f.resize(n+1, 0);

  for (int i = 0; i < n; i++) {
    int u,k;
    cin >> u >> k;
    
    vector<int> row(k);
    for (int j = 0; j < k; j++) {
      cin >> row[j];
    }
    
    list[u] = row;
  }

  dfs(1);

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

  return 0;
}