Go: package main

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

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <stack>
using namespace std;

int d[100];
int f[100];
int map[100][100];
int tim;
int n;
stack<int> s;
void visit(int);

int main(){
	tim=0;
	int i,j,k,u,v;
	for(i=0;i<100;i++) d[i]=-1; //?????¢??\
	for(i=0;i<100;i++) f[i]=-1;
	cin >> n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			map[i][j]=-1;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v;
			map[u-1][v-1]=1; //?????????????????????????????????????????????
		}
	}
	visit(0); //????????¢?????¢?´¢
	for(i=0;i<n;i++) cout<< i+1 <<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}

void visit(int a){
	s.push(a); //?????¨??°
	if(d[a]==-1){
		d[a]=++tim;
	}
	for(int i=0;i<n;i++){
		if(map[a][i]==1 && d[i]==-1){ //?????¢?´¢
			visit(i);
		}
	}
	s.pop();
	f[a]=++tim;
}

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

int a[100][100];
int n,p,q,r;
int T[100],F[100];
int Time = 0;
void dfs(int cur) {
	T[cur] = Time;
	Time += 1;
	for (int dst=0; dst < n; ++dst) {
		if(a[cur][dst] == 1 && T[dst] == -1) {
			dfs(dst);
		}
	}
	F[cur] = Time;
	Time += 1;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> p >> q;
		T[i] = -1;
		for (int j=0; j<q; ++j) {
			cin >> r;
			a[p-1][r-1] = 1;
		}
	}
	dfs(0);
	for (int i=0; i<n-1; ++i) {
		cout << i+1 << " " << T[i]+1 << " " << F[i]+1 << endl;
}
cout << n << " " << T[n-1]+1 << " " << F[n-1]+1
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };


int n;
vector<vec> v;
vec d, f;
int cnt=0;
vec memo;
void dfs(int num){
    d[num] = ++cnt;
    for(auto k: v[num]){
        if(memo[k]) continue;
        memo[k] = 1;
        dfs(k);
    }
    f[num] = ++cnt;
}

void solve() {
    cin >> n;
    v.resize(n);
    d.resize(n); f.resize(n);
    memo.resize(n, 0);
    rep(i, n){
        int a, b; cin >> a >> b;
        a--;
        rep(j, b){
            int c; cin >> c;
            c--;
            v[a].push_back(c);
        }
    }
    rep(i, n){
        if(memo[i]) continue;
        memo[i] = 1;
        dfs(i);
    }
    rep(i, n){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}

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

int n, G[101][101], S[101], T[101];

int dfs(int p, int s) {
    if (S[p] != 0) return 0;
    S[p] = s;
    s++;
    for (int i = 0; i < n; i++) {
        if (G[p][i] == 1) {
            s = max(s, dfs(i, s) + 1);
        }
    }
    T[p] = s;
    return s;
}


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

    for (int i = 0; i < n; i++)
        if (S[i] == 0) dfs(0, i);

    for (int i = 0; i < n; i++)
        printf("%d %d %d\n", i + 1, S[i], T[i]);

    return 0;
}

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

void dfs(int start, int n, int& time, std::vector<std::vector<int> >& G, std::vector<int>& D, std::vector<int>& F)
{
	D.at(start) = ++time;
	if (G.at(start).size() == 0)
	{
		F.at(start) = ++time;
		return;
	}
	for (int i = 0; i < G.at(start).size(); i++)
	{
		if (D.at(G.at(start).at(i)) == 0)
			dfs(G.at(start).at(i), n, time, G, D, F);
	}
	F.at(start) = ++time;
}


int main()
{	
	int n;
	std::cin >> n;
	std::vector<std::vector<int> > G;
	for (int i = 0; i < n; i++)
	{
		int nl;
		int m;
		std::vector<int> V;
		std::cin >> nl >>  m;
		for (int j = 0; j < m; j++)
		{
			int v;
			std::cin >> v;
			v--;
			V.push_back(v);
		}
		G.push_back(V);
	}
	std::vector<int> D(n, 0);
	std::vector<int> F(n, 0);
	int time = 0;
	for (int i = 0; i < n; i++)
	{
		if (D.at(i) == 0)
			dfs(i, n, time, G, D, F);	
	}
	
	for (int i = 0; i < n; i++)
	{
		std::cout << i + 1 << ' ' << D.at(i) << ' ' << F.at(i) << '\n';
	}
	return 0;
}