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>
#define REP(i,n) for (int i=0;i<(n);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int N;
int tt = 0;
vector< vector<int> > G;
vector<int> H, d, f;
int itrNum[100001];
stack<int> S;

void dfs(int u){
    S.push(u);
    H[u] = 0;

    while(!S.empty()){
        u = S.top();  // ?¨????????????????
        if(d[u] == 0) d[u] = ++tt;
        auto itr_v = next(G[u].begin(), itrNum[u]);
        if(itr_v != G[u].end()){
            itrNum[u]++;
            int v = *itr_v;
            if(H[v] == -1){
                H[v] = 0;
                S.push(v);
            }
        }else{
            S.pop();
            H[u] = 1;
            f[u] = ++tt;
        }
    }
}

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

    cin >> N;
    G = vector<vector<int> >(N);
    H = vector<int>(N, -1);
    d = vector<int>(N, 0);
    f = vector<int>(N, 0);
    memset(itrNum, 0, sizeof(itrNum));
    REP(i, N){
        int u,k;
        cin >> u >> k;
        u--;
        REP(j ,k){
            int v;
            cin >> v;
            v--;
            G[u].pb(v);
        }
    }

    REP(i, N) if(H[i] == -1) dfs(i);
    REP(i, N){
        cout << i+1 << " " << d[i] << " " << f[i] << "\n";
    }
    return 0;
}

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

using namespace std;

void dfs(int n, vector<vector<int> > &G, int s, int *d, int *f, int &t) {
    d[s] = t++;
    for (int i = 0; i < G[s].size(); i++) {
        int v = G[s][i];
        
        if (d[v] != -1)
            continue;

        dfs(n, G, v, d, f, t);
    }
    f[s] = t++;
}

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

    int *f = new int[n], *d = new int[n];
    for (int i = 0; i < n; i++)
        f[i] = d[i] = -1;

    int t = 1;
    for (int i = 0; i < n; i++) {
        if (d[i] == -1)
            dfs(n, G, i, d, f, t);
    }

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

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<utility>
using namespace std;
vector<int> l[101];
int matrix[100][100];
pair<int,int> t[101];
int tim=0;
void dfs(int cur)
{
    tim+=1;
    t[cur].first=tim;
    //cerr<<"visiting "<<cur<<' '<<tim<<endl;
    
    for(int i=0;i<l[cur].size();i++)
    {
        if(matrix[cur-1][l[cur][i]-1]==1)
        {
            dfs(l[cur][i]);
        }
    }
    
    tim+=1;
    t[cur].second=tim;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            int tmp;
            cin>>tmp;
            l[u].push_back(tmp);
        }
    }
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            matrix[i][j]=0;
        }
    }
    for(int i=1;i<n+1;i++)
    {
        for(int j=0;j<l[i].size();j++)
        {
            matrix[i-1][l[i][j]-1]=1;
        }
    }
    
    dfs(1);
    
    for(int i=1;i<n+1;i++)
    {
        cout<<i<<" "<<t[i].first<<" "<<t[i].second<<endl;
    }
}

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

const static int MAX = 100;
int G[MAX][MAX];
int nt[MAX];
int n;

int nextNode(int x){
    for(int i = nt[x]; i < n; i++){
	if(G[x][i] == 1){
	    nt[x] = i + 1;
	    return i;
	}
    }
    return -1;
}

int main(void){
    std::stack<int> st;
    int color[MAX], a[MAX], b[MAX];
    int u, k, v, time;

    time = 0;
    std::cin >> n;

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

    for(int i = 0; i < n; i++){
	std::cin >> u >> k;
	u--;
	for(int j = 0; j < k; j++){
	    std::cin >> v;
	    v--;
	    G[u][v] = 1;
	}
    }

    for(int i = 0; i < n; i++){
	if(color[i] == 0){
	    st.push(i);
	    color[i] = 1;
	    a[i] = ++time;
	}
	while(!st.empty()){
	    int cur = st.top();
	    int next = nextNode(cur);
	    if(color[next] == 0 && next != -1){
	        st.push(next);
	        color[next] = 1;
	        a[next] = ++time;
	    }
	    if(next == -1){
		st.pop();
		b[cur] = ++time;
	    }
	}
    }

    for(int i = 0; i < n; i++){
        std::cout << i+1 << " " << a[i] << " " << b[i] << std::endl;
    }


    return 0;

}

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

int DFS(bool path[110][110],int begin[],int end[],int v,int n,int t){
    t++;
    begin[v]=t;
    for(int i=0;i<n;i++){
        if(path[v][i]&&begin[i]==0){
            t=DFS(path,begin,end,i,n,t);
        }
    }
    t++;
    end[v]=t;
    return t;
}

int main(void){
    int n,u,k,i,j,x,t;
    bool path[110][110];
    int begin[110],end[110];
    memset(path,0,sizeof(path));
    memset(begin,0,sizeof(begin));
    cin>>n;
    for(i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(j=0;j<k;j++){
            cin>>x;
            x--;
            path[u][x]=true;
        }
    }
    
    t=0;
    for(i=0;i<n;i++){
        if(begin[i]==0){
            t=DFS(path,begin,end,i,n,t);
        }
    }
    
    for(i=0;i<n;i++){
        cout<<i+1<<" "<<begin[i]<<" "<<end[i]<<endl;
    }
    
    return 0;
}