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>
//cout<<setprecision(1)<<fixed<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N=100000;
const int INF = 0x3f3f3f3f;
#define eps 1e-7
//#define Kongxiangzhouye
int n;
int a[123][123];
int st[123];
int ed[123];
int now;
void dfs(int local){
	st[local]=now++;
	int flag=1;
	for(int i=1;i<=n;i++){
		if(a[local][i]==1){
			if(st[i]==0){
				flag=0;
				dfs(i);
			}
		}
	}
	ed[local]=now++;
}
int main(){
	ios::sync_with_stdio(false);
	#ifdef Kongxiangzhouye
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	while(cin>>n){
		memset(a,0,sizeof(a));
		memset(st,0,sizeof(st));
		memset(ed,0,sizeof(ed));
		for(int i=0;i<n;i++){
			int t,m;
			cin>>t>>m;
			for(int i=0;i<m;i++){
				int te;
				cin>>te;
				a[t][te]=1;
			}
			now=1;
		}
		dfs(1);
		for(int i=1;i<=n;i++){
			cout<<i<<" "<<st[i]<<" "<<ed[i]<<endl;
		}
	}
	return 0;
}

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

int n;
int cnt1 = 0; 
vector<int> d(n);
vector<int> f(n);
void dfs(const Graph &G, int v){
    cnt1++;
    d[v - 1] = cnt1;
    for(auto nv : G[v - 1]){
        if(d[nv - 1] != 0) continue;
        dfs(G, nv);
    }
    cnt1++;
    f[v - 1] = cnt1;
}

int main(){
    cin >> n;
    Graph G(n); 
    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        if(b == 0) continue;
        for(int j = 0; j < b; j++){
            int x; cin >> x;
            G[a - 1].push_back(x);
        }
    }
    d.assign(n, 0);
    f.assign(n, 0);
    for(int i = 1; i <= n; i++){
      if(d[i - 1] == 0) dfs(G, i);
    }
    for(int i = 1; i <= n; i++){
        cout << i << " " << d[i - 1] << " " << f[i - 1] << endl; 
    }
}

C++: #include <iostream>
#define MAX 101

using namespace std;

bool flag[MAX][MAX];
int t[MAX][2];
int n;

void dfs(int num){
	static int cnt = 1;
	
	if(t[num][0] == 0)t[num][0] = cnt++;
	else return;
	for(int i=1;i<=n;++i){
		if(flag[num][i] == true){
			dfs(i);
		}
	}
	t[num][1] = cnt++;
}

int main(){
	int u, k, v, i, j; 
	
	cin >> n;
	for(i=1;i<=n;++i){
		cin >> u >> k;
		for(j=0;j<k;++j){
			cin >> v;
			flag[u][v] = true;
		}
		 
	}
	for(int i=1;i<=n;++i)dfs(i);
	for(int i=1;i<=n;++i)cout << i << " " << t[i][0] << " " << t[i][1] << endl;
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

using Graph = vector<vector<ll>>;
Graph G;
ll d[110], f[110];

void DFS(ll v, ll &t)
{
	if (d[v] != -1) return;
	d[v] = t;

	++t;
	for (auto &nv : G[v])
	{
		DFS(nv, t);
	}
	f[v] = t;
	++t;
}

int main(int argc, char **argv)
{
	ll N; cin >> N;
	G.resize(N);
	for (ll i = 0; i < N; ++i)
	{
		ll n, k; cin >> n >> k;
		--n;
		for (ll j = 0; j < k; ++j)
		{
			ll v; cin >> v;
			--v;
			G[n].push_back(v);
		}
		sort(G[n].begin(), G[n].end());
	}
	fill(d, d+110, -1);
	fill(f, f+110, -1);

	ll t = 1;
	for (ll v = 0; v < N; ++v)
	{
		if (d[v] == -1)
			DFS(v, t);
	}

	for (ll i = 0; i < N; ++i)
	{
		std::cout << i + 1 << " " << d[i] << " " << f[i] << std::endl;
	}
}

C++: //?????????????????¢?´¢
//??????????????????????????????????????¢?´¢
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
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;
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;
}

void dfs_visit(int r){
    for(int i = 0; i < n; i++) nt[i] = 0;
    stack<int> S;
    
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;
    
    while(!S.empty()){
        int u = S.top();
        int v = next(u);
        
        if(v != -1){
            if(color[v] == WHITE){
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }
        else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs(){
    int u;
    for(int i = 0; i < n; i++) nt[i] = 0;
    
    for( u = 0; u < n; u++){
        //????¨????u?????¢??????????????????dfs
        if(d[u] == WHITE) dfs_visit(u);
    }
    
    for( int i = 0; i < n; i++){
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main(void){
    int u, v, k, j,i;
    
    cin >> n;
    
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++) M[i][j] = 0;
   
    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;
}

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

using namespace std;

#define MAX 110
int num;
int matrix[MAX][MAX];
int dst[MAX];

void input(){
    cin >> num;
    for(int i=0;i<MAX;i++){
        dst[i] = -1;
        for(int j=0;j<MAX;j++){
            matrix[i][j] = 0;
        }
    }
    for(int i=1;i<=num;i++){
        int v; cin >> v;
        int tmp; cin >>tmp;
        for(int j=0;j<tmp;j++){
            int vi; cin >> vi;
            matrix[v-1][vi-1] = 1;
        }
    }
}

void dfs(){
    stack<int> S;
    S.push(0);
    dst[0] = 0;
    while(S.size() != 0){
        int cur = S.top();
        S.pop();
        for(int i=0;i<num;i++){
            if(matrix[cur][i]==1){
                if(dst[i]==-1 ){
                    S.push(i);
                    dst[i] = dst[cur] + 1;
                }
            }
        }
    }
    for(int i=0;i<num;i++){
        cout << i+1 << " " <<  dst[i] << endl;
    }
}

int main(){
    input();
    dfs();
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
static const int N=100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
int n,M[N+1][N+1];
int color[N+1],d[N+1],f[N],tt;
void dfs_visit(int u){
    int v;
    color[u]=GRAY;
    d[u]=++tt;
    for(int v=1;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=1;u<=n;u++)color[u]=WHITE;
    tt=0;
    for(int u=1;u<=n;u++){
        if(color[u]==WHITE)dfs_visit(u);
    }
    for(int u=1;u<=n;u++)
        cout<<u<<" "<<d[u]<<" "<<f[u]<<"\n";
}
int main(){
    int u,v,k;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)
            M[i][j]=0;
    }
    for(int i=1;i<=n;i++){
        cin>>u>>k;
        for(int j=1;j<=k;j++){
            cin>>v;
            M[u][v]=1;
            
        }
    }
    dfs();
    return 0;
}