Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

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

using namespace std;

using ll = long long;

ll MAX_N = 1e5;
vector<vector<ll> > graph(MAX_N);
vector<bool> visited(MAX_N);

// ALDS1_11_B
vector<ll> d(MAX_N);
vector<ll> f(MAX_N);
ll t = 0;

// O(E)
void dfs(ll u){
    visited[u] = true;
    // visit v
    d[u] = ++t;
    for(ll v: graph[u]){
        if(!visited[v]){
            dfs(v);
        }
    }
    f[u] = ++t;
}

// ALDS1_11_B: verified
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    for(ll i=0;i<n;i++){
        ll u, k; cin >> u >> k;
        vector<ll> vs;
        for(ll j=0;j<k;j++){
            ll v; cin >> v;
            vs.push_back(v);
        }
        sort(vs.begin(), vs.end());
        for(ll j=0;j<k;j++){
            ll v = vs[j];
            graph[u - 1].push_back(v - 1);
        }
    }
    for(int i=0;i<n;i++){
        if(!visited[i]) dfs(i);
    }
    for(int i=0;i<n;i++) cout << i + 1 << " " << d[i] << " " << f[i] << endl;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define white 0
#define gray 1
#define black 2
const int N=100;
int n,color[N],c[N][N],tt,f[N],d[N];
void dfs_visit(int u){
    color[u]=gray;
    f[u]=++tt;
    for(int v=0;v<n;v++){
        if(c[u][v]==0)continue;
        if(color[v]==white){
            dfs_visit(v);
        }
    }
    color[u]=black;
    d[u]=++tt;
}
void dfs(){
    memset(color,0,sizeof(color));
    memset(f,0,sizeof(f));
    memset(d,0,sizeof(d));
    tt=0;
    for(int u=0;u<n;u++){
        if(color[u]==white)
        dfs_visit(u);
    }
    for(int u=0;u<n;u++)
    {
        cout<<u+1<<" "<<f[u]<<" "<<d[u]<<endl;
    }
}
int main(){
    int u,v,k;
    cin>>n;
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++){
        cin>>u>>k;u--;
        for(int j=0;j<k;j++){
            cin>>v;v--;
            c[u][v]=1;
        }
    }
    dfs();
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vqi = vector<queue<int>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void dfs(vqi &g, vi &d, vi &f, int v, int &t) {
  if (d[v] && g[v].empty()) {
    t--;
    return;
  }

  if (!d[v]) d[v] = t;

  while (!g[v].empty()) {
    int next = g[v].front(); g[v].pop();
    if (!d[next] )dfs(g, d, f, next, ++t);
  }

  f[v] = max(++t, f[v]);
}

int main() {
  int n;
  cin >> n;
  
  vqi g(n);
  rep(i, n) {
    int u, k;
    cin >> u >> k;

    rep(j, k) {
      int v;
      cin >> v;
      g[u - 1].push(v - 1);
    }
  }

  vi d(n), f(n);
  stack<int> s;
  s.push(0);

  int t = 1;
  rep(i, n) {
    dfs(g, d, f, i, t);
    t++;
  }

  rep(i, n) printf("%d %d %d\n", i + 1, d[i], f[i]);
}

C++: 
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll mod=1e9+7;
const ll white=0;
const ll gray=1;
const ll black=2;

ll n;
ll m[105][105];
ll color[105];
ll d[105];
ll f[105];
ll tt;

void dfs_visit(ll u){
    color[u]=gray;
    d[u]=++tt;
    rep(v,n){
        if(m[u][v]==0) continue;
        if(color[v]==white){
            dfs_visit(v);
        }
    }
    color[u]=black;
    f[u]=++tt;
}
void dfs(){
    rep(u,n){
        color[u]=white;
    }
    tt=0;
    rep(u,n){
        if(color[u]==white){
            dfs_visit(u);
        }
    }
    rep(u,n){
        cout << u+1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main()
{
    cin >> n;
    rep(i,n){
        rep(j,n){
            m[i][j]=0;
        }
    }
    rep(i,n){
        ll u,k;
        cin >> u >> k;
        u--;
        rep(j,k){
            ll v;
            cin >> v;
            v--;
            m[u][v]=1;
        }
    }
    dfs();
    return 0;
}

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

#define NUM 100
int node_num;
int V[NUM + 1][NUM + 1];
int d[NUM + 1];
int f[NUM + 1];
string color[NUM + 1];
int t;
int pos;
stack<int> s;

void createAdj(int n){
    for(int i = 1; i < NUM; i++){
        for(int j = 1; j < NUM; j++){
            V[i][j] = 0;
        }
    }

    for(int i = 0; i < n; i++){
        int num1;
        scanf("%d", &num1);

        int n;
        scanf("%d", &n);

        int num2;
        for(int j = 0; j < n; j++){
            scanf("%d", &num2);
            V[num1][num2] = 1;
        }
    }
}

int search(int n){
    for(int i = 1; i <= node_num; i++) {
        if(V[n][i] == 1 && color[i] == "white")
            return i;
        if(V[i][n] == 1 && color[i] == "white")
            return i;
    }
    return -1;
}

void dfs_init(){
    t = 0;
    for(int i = 0; i < NUM; i++){
        color[i] = "white";
    }
}

void dfs(){
    s.push(1);
    pos = 1;
    t++;
    color[1] = "grey";
    d[1] = t;

    while(s.size()){
        int u = s.top();
        int next_node = search(u);
        if(next_node != -1){
            pos = next_node;
            s.push(next_node);
            pos = next_node;
            t++;
            color[next_node] = "grey";
            d[next_node] = t;
        }else{
            s.pop();
            color[u] = "black";
            t++;
            f[u] = t;
        }
    }
}

void print(){
    for(int i = 1; i <= node_num; i++){
        printf("%d %d %d\n", i, d[i], f[i]);
    }
}

int main(void){
    scanf("%d", &node_num);
    createAdj(node_num);

    dfs_init();
    dfs();

    print();
}