Go: package main

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

func main() {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	nextInt := func() int { scn.Scan(); r, _ := strconv.Atoi(scn.Text()); return r }
	w := bufio.NewWriter(os.Stdout)

	n := nextInt()
	vecs := make([][]int, n)
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			vecs[u-1] = append(vecs[u-1], nextInt()-1)
		}
	}

	ds := make([]int, n)
	fs := make([]int, n)
	founds := make([]bool, n)
	t := 0
	for i := range founds {
		if !founds[i] {
			t = dfs(vecs, ds, fs, founds, i, t)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(w, i+1, ds[i], fs[i])
	}

	w.Flush()
}

func dfs(vecs [][]int, ds, fs []int, founds []bool, i, t int) (time int) {
	t++
	ds[i] = t
	founds[i] = true
	for _, v := range vecs[i] {
		if !founds[v] {
			t = dfs(vecs, ds, fs, founds, v, t)
		}
	}
	t++
	fs[i] = t

	return t
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;
using Graph = vector<vector<int>>;

// 難しいね
int main()
{
    // input
    int n;
    cin >> n;
    vector<queue<int>> q(n+1);
    rep2(i,1,n+1){
        int id, num;
        cin >> id >> num;
        rep(j,num){
            int temp;
            cin >> temp;
            q[i].push(temp);
        }
    }


    // solve
    vector<int> d(n+1), f(n+1);
    stack<int> place;
    place.push(1);
    int time = 0;
    while(place.size()){
        int now = place.top();
        if(!d[now]) d[now] = ++time;

        while(q[now].size()){
            if(!d[q[now].front()]){
                place.push(q[now].front());
                q[now].pop();
                break;
            }else{
                q[now].pop();
            }
        }
        if(now == place.top()){
            place.pop();
            f[now] = ++time;
        }
        if(place.size() == 0){
            rep2(i,1,n+1){
                if(d[i]==0){place.push(i); break;}
            }
        }
    }

    // output
    rep2(i,1,n+1) cout << i << " " << d[i] << " " << f[i] << endl;
    return 0;
}

C++: #include <iostream>

using namespace std;

#define N_MAX 100

int Adj[N_MAX][N_MAX] = {};
int Chk[N_MAX][2] = {};
int search_time = 1;

void dfs(int v, int num_node);

int main()
{
    int n, i, u, k, v, j;

    cin >> n;

    //??£??\???????????????
    for (i = 0; i < n; i++) {
        cin >> u >> k;
        while (k-- > 0) {
            cin >> v;
            Adj[u-1][v-1] = 1;
        }
    }
/*
    cout << "show Adjacency matrix" << endl;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n ; j++) {
            if (j == n - 1)
                cout << Adj[i][j] << endl;
            else
                cout << Adj[i][j] << ' ';
        }
    }
*/
    //??¢?´¢??????
//    dfs(1, n);
    for (i = 1; i <= n; i++) {
        if (Chk[i-1][0] == 0)
            dfs(i, n);
    }

    for(i = 0; i < n; i++) {
        cout << i+1 << ' ' << Chk[i][0] << ' ' << Chk[i][1] << ' ' <<  endl;
    }

    return 0;
}

void dfs(int v, int num_node) {

//    cout << "dfs node : " << v << " time : " << search_time << endl;

    int i;
    //v???????????????????¨????
    if (Chk[v-1][0] == 0) //????????????node?????´???
        Chk[v-1][0] = search_time++;
    else {                //??¢??\???node?????´???
    //    search_time++;
        return;
    }

    //v???????????¢?´¢
    for (i = 1; i <= num_node; i++) {
        if (Adj[v-1][i -1] == 1) {
            dfs(i, num_node);
        }
    }

    //?????±??¨?????§??¢?´¢??????????????????
    //v???????????????????¨????
    Chk[v-1][1] = search_time++;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n, m[N][N];
int color[N], d[N], f[N], tt;
void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for (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() {
    int u;
    for (u = 0; u < n; u++)color[u] = WHITE;
    tt = 0;
    for (u = 0; u < n; u++) {
        if (color[u] == WHITE)dfs_visit(u);
    }
    for (u = 0; u < n; u++) {
        printf("%d %d %d\n", u + 1, d[u], f[u]);
    }
}
int main() {
    int u, v, k, i, j;
    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 <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
#define MAX 100
#define WHITE 1
#define GRAY 2
#define BLACK 3

int n;
int graph[MAX][MAX];
stack<int> st;
int *d,*f,*v;
int *color;
int tm;

int next(int k){
	for(int i = v[k];i < n;i++){
		v[k]++;
		if(color[i] == WHITE && graph[k][i] == 1) return i;
	}
	return -1;
}

void dfs(int k){
	for(int i = 0;i < n;i++) v[i] = 0;

	st.push(k);
	d[k] = ++tm;
	color[k] = GRAY;

	while(!st.empty()){
		int m = next(st.top());
		if(m != -1){
		  if(color[m] == WHITE){
				st.push(m);
				color[m] = GRAY;
				d[m] = ++tm;
			}
		}else{
			f[st.top()] = ++tm;
			color[st.top()] = BLACK;
			st.pop();
		}
	}
}


int main(){
	cin >> n;
	//?????????
	color = new int[n];
	d = new int[n];
	f = new int[n];
	v = new int[n];
	for(int i = 0;i < n;i++){
		color[i] = WHITE;
		d[i] = 0;
		f[i] = 0;
		for(int j = 0;j < n;j++){
			graph[i][j] = 0;
		}
	}
	//data input
	for(int i = 0;i < n;i++){

		int t,k,p;

		cin >> t >>  k;
		for(int j = 0;j < k;j++){
			cin >> p;
			p--;
			graph[i][p] = 1;
		}
	}
	tm = 0;
	for(int i = 0;i < n;i++){if(color[i] == WHITE) 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;
const int MAXN = 1000;
int n;
int d[MAXN];
int f[MAXN];
int t;
void solve(int current,vector<vector<int> > &g){
  if(d[current] > 0)return;
  t++;
  d[current] = t;
  for(int next:g[current]){
    solve(next,g);
  }
  t++;
  f[current] = t;
}

int main(){
  cin >> n;
  vector<vector<int> > g(n+1);
  for(int i = 1;i <= n;i++){
    int u,k;
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      int v;
      cin >> v;
      g[i].push_back(v);
    }
  }
  solve(1,g);
  for(int i = 1;i <= n;i++){
    cout << i << ' ' << d[i] << ' ' << f[i] << endl;
  }
}