Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

C++: #include <bits/stdc++.h>

using namespace std;
int t;

void dfs(vector<vector<bool> >& A, vector<vector<int> >& B, int s, int n, vector<int> & u){
    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;
            if(u[i] == 0){
                u[i] = 1;
                dfs(A, B, i, n, u);
            }
        }
        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));
    vector<int> u(n, 0);
    u[0] = 1;
    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;
    for(int k = 0; k < n; k++){
        if(B[k][1] == 0) dfs(A, B, k, n, u);
    }
    

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

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;
int dfs(int n,int x,vector<int> k,vector<vector<int>> v,vector<int> &a,vector<int> &b,int &count);


int main(){
	int n;
	cin>>n;
	vector<vector<int> > v(n);
	vector<int> k(n);
	int x;
	rep(i,n){
		cin>>x;
		cin>>k[i];
		v[i].resize(k[i]);
		rep(j,k[i]){
			cin>>v[i][j];
			v[i][j]--;
		}
	}
	vector<int> a(n),b(n);
	int count=1;
	a[0]=1;
	dfs(n,0,k,v,a,b,count);

	rep(i,n){
		if(a[i]==0){
			dfs(n,i,k,v,a,b,count);
		}
	}


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

	return 0;
}
int dfs(int n,int x,vector<int> k,vector<vector<int>> v,vector<int> &a,vector<int> &b,int &count){
	/*if(k[x]==0){
		count++;
		a[x]=count;
	}*/
	rep(i,k[x]){
		if(a[v[x][i]]==0){
			count++;
			a[v[x][i]]=count;
			dfs(n,v[x][i],k,v,a,b,count);
		}
		if(i==k[x]-1){
			k[x]=0;
		}
	}
	if(k[x]==0){
		count++;
		b[x]=count;
	}
	return 0;
}

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

using namespace std;

static const int N = 100; // 1 <= n <= 100
static const int WHITE = 0; // 未訪問は0
static const int GRAY = 1; // 訪問中は1
static const int BLACK = 2; // 訪問完了は2

int n; // 頂点数n
vector<vector<int>> M(N, vector<int>(N,0)); // M[u][v]：uからvに出ているか否か
vector<int> color(N), d(N), f(N); // d(i)：頂点i発見時刻，f(i)：頂点i完了時刻
int tt; // 経過時間tt
vector<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;
}

// 地点rについてスタックを用いた深さ優先探索
void dfs_visit(int r) {
    //初期化
    for ( int i = 0; i < n; i++ ){
        nt[i] = 0;
    }
    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    
    tt++;
    d[r] = tt;
    
    while ( !S.empty() ) {
        int u = S.top();
        int v = next(u);
        if ( v != -1 ) {
            if ( color[v] == WHITE ) {
                color[v] = GRAY;
                tt++;
                d[r] = tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            tt++;
            f[u] = tt;
        }
    }
}

void dfs() {
    // 初期化
    for ( int i = 0; i < n; i++ ) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;
    
    // 未訪問のuを始点として深さ優先探索
    for ( int u = 0; u < n; u++ ){
        if ( color[u] == WHITE ){
            dfs_visit(u);
        }
    }
    
    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++){
        cin >> u >> k;
        u--;
        for(int j=0;j<k;j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
        
        dfs();
        return 0;
    }
}

C++: #include<cstdio>

class Graph{
    int n;
    int **G;
    int *seen;
    int *time_d;
    int *time_f;
    
    public: Graph(int _n){
        n = _n;
        G = new int*[n+1];
        seen = new int[n+1];
        time_d = new int[n+1];
        time_f = new int[n+1];
        for(int i = 0;i <=n;++i){
            G[i] = new int[n+1];
            time_d[i] = 0;
            time_f[i] = 0;
        }
        for(int i = 0;i <= n;++i){
            for(int j = 0;j <= n;++j){
                G[i][j] = 0;
            }
        }
    }
    
    public: void BuildMatrix(){
        int u,k,v;
        for(int i = 0;i < n;++i){
            scanf("%d %d",&u,&k);
            for(int j = 0;j < k;++j){
                scanf("%d",&v);
                G[u][v] = 1;
            }
        }
    }
    
    public: void PrintMatrix(){
        for(int i = 1;i <= n;++i){
            for(int j = 1;j <n;++j){
                printf("%d ",G[i][j]);
            }
            printf("%d\n",G[i][n]);
        }
    }
    
    public :void DoDFS(){
        int c = 0;
        for(int i = 0;i <= n;++i) seen[i] = 0;
        DFS(1,c);
        for(int i = 1;i <= n;++i){
            if(seen[i] != 1) DFS(i,c);
        }
        for(int i = 1;i <= n;++i){
            printf("%d %d %d\n",i,time_d[i],time_f[i]);
        }
    }
    
    void DFS(int s,int& cnt){
        cnt++;
        seen[s] = true;
        time_d[s] = cnt;
        for(int j = 1;j <= n;++j){
            if(G[s][j] == 1 && seen[j] == 0){
                DFS(j,cnt);
            }
        }
        cnt++;
        time_f[s] = cnt;
    }
    
};

int main(){
    int n;
    scanf("%d",&n);
    Graph G(n);
    G.BuildMatrix();
    G.DoDFS();
}