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<cstdio>
#include<cstdlib>
#include<string.h>
#include<stack>
using namespace std;

int n;
int m[100][100], d[100], f[100];
int t = 0;
char c[100];
stack<int> s;

int next(int u){
  for(int i = 0; i < n; i++){
    if(m[u][i] == 1 && c[i] == 'w') return i;
  }
  return 0;
}

void dfs(int u){
  s.push(u);
  c[u] = 'g';
  d[u] = ++t;

  while(s.empty() == 0){
    u = s.top();
    int v = next(u);
    if(c[v] == 'w'){
      c[v] = 'g';
      d[v] = ++t;
      s.push(v);
    }
    else{
      s.pop();
      c[u] = 'b';
      f[u] = ++t;
    }
  }
}


int main(){

  cin >> n;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      m[i][j] = 0;
      c[i] = 'w';
    }
  }

  for(int i = 0; i < n; i++){
    int id, k, x;
    cin >> id >> k;
    for(int j = 0; j < k; j++){
      cin >> x;
      m[i][x - 1] = 1;
    }
  }

  for(int i = 0; i < n; i++){
    if(c[i] != 'b') dfs(i);
  }

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

  return 0;
}

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

vector<int> graph[100];
int start[100],endt[100];
int cnt;

void dfs(int num){
	start[num] = ++cnt;
	for(int i = 0;i < graph[num].size();i++){
		if(graph[num][i] != num && !endt[graph[num][i]]) dfs(graph[num][i]);
	}
	endt[num] = ++cnt;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int now,m;
		cin >> now >> m;
		for(int j = 0;j < m;j++){
			int t;
			cin >> t;
			graph[now - 1].push_back(t - 1);
		}
	}
	dfs(0);
	for(int i = 0;i < n;i++){
		if(!endt[i]) dfs(i);
	}
	for(int i = 0;i < n;i++){
		cout << i + 1 << " " << start[i] << " " << endt[i] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long i64;typedef vector<int> ivec;typedef vector<string> svec;

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;

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

int main(){
	int u,v,k;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		u--;
		for(int j=0;j<k;j++){
			scanf("%d",&v);
			v--;
			M[u][v] = 1;
		}
	}
	dfs();
	return 0;
}

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

typedef vector<vector<int>> Graph;

int N;
Graph G;
vector<int> td, tf;
int timestamp;

void dfs(int v){
	td[v] = timestamp++;

	for(int i=0; i<G[v].size(); i++){
		int u = G[v][i];
		if(td[u] == -1){
			dfs(u);
		}
	}

	tf[v] = timestamp++;
}

int main(){
	cin >> N;
	G.resize(N);
	td.resize(N, -1);
	tf.resize(N, -1);

	for(int i=0; i<N; i++){
		int x; cin >> x; x--;
		int k; cin >> k;
		for(int i=0; i<k; i++){
			int y; cin >> y; y--;
			G[x].push_back(y);
		}
	}

	timestamp = 1;

	for(int i=0; i<N; i++) if(td[i] == -1)
		dfs(i);

	for(int i=0; i<N; i++){
		cout << i+1 << " " << td[i] << " " << tf[i] << endl;
	}

	return 0;
}

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

vector<vector< int> > tstamp;
int n;
vector<vector<int> > G;
int ttime=0;

void tansaku(int i){
  ttime++;
  if (!tstamp[i][0]) tstamp[i][0] = ttime;
  for (int j=0;j<n;j++)
    if(G[i][j]) tansaku(j);
  tstamp[i][1] = ++ttime;
}




int main(){
  cin >> n;
  G.assign(n, vector<int>(n,0));
  for (int i=0;i<n;i++){
    int u,k;
    cin >> u >> k;
    for (int j=0;j<k;j++){
      int v;
      cin >> v;
      G[u-1][v-1] = 1;
    }
  }
  tstamp.assign(n,vector<int>(2,0));
  tansaku(0);

  for(int id=0;id<n;id++){
    cout << id+1 << " " << tstamp[id][0] << " " << tstamp[id][1] << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力

vector<vector<ll> > G;
vector<bool> seen;
vector<ll> d;
vector<ll> f;
ll cnt=1;
//ll fcnt=1;
void dfs(ll v){
    seen[v] = 1;
    d[v] = cnt;
    cnt++;
    rep(i,G[v].size()){
        if(seen[G[v][i]] == 0){
            dfs(G[v][i]);
        }
    }
    f[v] = cnt;
    cnt++;
}

int main() {
    ll n;
    cin >> n;
    G.resize(n);
    seen.resize(n);
    d.resize(n);
    f.resize(n);

    rep(i,n){
        ll u,k;
        cin>>u>>k;
        rep(j,k){
            ll v;
            cin>>v;
            G[i].pb(v-1);
        }
    }
    rep(i,n){
        if(seen[i]==0)
            dfs(i);
    }

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


    return 0;
    

}