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;
int t;

void dfs(vector<vector<bool> >& A, vector<vector<int> >& B, int s, int n){
    for(int i = 0; i < n; i++){
        if(i == 0){
            if(B[s][1] == 0){
                B[s][1] = t;
                t++;
            }
        }
        if(A[s][i] == true){
            A[s][i] = false;
            dfs(A, B, i, n);
        }
        if(i == n-1){
            if(B[s][2] == 0){
                B[s][2] = t;
                t++;
            }
        }
    }
}

int main(void){

    //??£??\??????????????£??\???????????????
    int n, k;

    cin >> n;
    vector<vector<bool> > A(n, vector<bool>(n, false));
    for(int i = 0; i < n; i++){
        cin >> k >> k;
        for(int j = 0; j < k; j++){
            int input;
            cin >> input;
            A[i][input-1] = true;
        }
    }

   

    vector<vector<int> > B(n, vector<int>(3, false));
    for(int i = 0; i < n; i++){
        B[i][0] = i + 1;
    }

    t = 1;
    dfs(A, B, 0, n);

    //??????
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j != n-1) cout << B[i][j] << " ";
            else cout << A[i][j];
        }
        cout << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

ll w[110][110];
ll d[110], f[110];
int color[110];
ll n, tt;
int White = 0, Gray = 1, Black = 2;

void dfs_visit(int u){
    int v;
    color[u] = Gray;
    d[u] = ++tt;
    Rep(v, 1, n){
        if(w[u][v] == 0) continue;
        if(color[v] == White){
            dfs_visit(v);
        }
    }
    color[u] = Black;
    f[u] = ++tt;
}

void dfs(){
    Rep(i, 1, n) color[i] = White; // 0:未訪問 1:訪問途中 2:訪問済
    
    tt = 0;
    Rep(u, 1, n){
        if(color[u] == White) dfs_visit(u);
    }

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

}

void solve() {
    cin >> n;
    Rep(i, 1, n) Rep(j, 1, n) w[i][j] = 0;
    Rep(i, 1, n){
        ll u, k; cin >> u >> k;
        rep(i, 0, k){
            ll v; cin >> v;
            w[u][v] = 1;
        }
    }

    dfs();

    return;
}

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

    solve();
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> adjlist;
int t=1;
vector<int> d;
vector<int> f;
void input(int n){
	vector<int> f={0,0};
	adjlist.push_back(f);
  for(int i=0;i<n;i++){
    vector<int> list;
    int ln;
    cin>>ln;
    list.push_back(ln);
    cin>>ln;
    list.push_back(ln);
    for(int j=0;j<ln;j++){
      int an;
      cin>>an;
      list.push_back(an);
    }
    adjlist.push_back(list);
  }
}

void depth_search(int id){
	vector<int> list=adjlist[id];
	for(int j=0;j<list[1];j++){
		if(d[list[2+j]]<0){
			d[list[2+j]]=++t;
			depth_search(list[2+j]);
		}
	}
	f[id]=++t;
}
 
void print(int n){
  for(int i=1;i<n+1;i++){
    cout<<i<<' '<<d[i]<<' '<<f[i]<<endl;
  }
}
int main(){
  int n;
  cin>>n;
	d=vector<int> (n+1,-1);
	f=vector<int> (n+1,-1);
	d[1]=1;
	f[1]=1;
  input(n);
  depth_search(1);
  print(n);
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;
int n,v[100+1][100+1]={},color[100+1]={},tim,d[1000],f[1000];
void visit(int u){
  color[u]=1;
  d[u]=++tim;
  rep(i,n){
    if(v[u][i]==0)continue;
    if(color[i]==0)
      visit(i);
  }
  color[u]=2;
  f[u]=++tim;
}
void dfs(){
  rep(i,n)color[i]=0;
  tim = 0;
  rep(i,n){
    if(color[i]==0)
      visit(i);
  }
}

int main(){
  cin>>n;
  int u,k,in;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>in;
      v[u-1][in-1]=1;
    }
  }
  dfs();
  rep(i,n)cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

stack<int> S;
int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N]; //未訪問な次の頂点を保持

//未訪問な次の頂点を返す．全て訪問済みなら-1を返す
int next(int u){
    for(int v = nt[u]; v < n; v++){
        nt[u] = v + 1;
        if(M[u][v]) return v;
    }
    return -1;
}

void dfs_visit(int i){
    S.push(i);
    color[i] = GRAY;
    d[i] = ++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{
            color[u] = BLACK;
            f[u] = ++tt;
            S.pop();
        }
    }
}

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

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

    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--; //0オリジンに変換
        for(int j = 0; j < k; j++){
            cin >> v;
            v--; //0オリジンに変換
            M[u][v] = 1;
        }
    }

    dfs();
    
    return 0;

}