Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
static const int N=105;
int M[N+1][N+1];
void graph(int n){
    for(int i=1;i<=n;i++){
        int garbage;cin>>garbage;
        int k;cin>>k;
        for(int j=1;j<=k;j++){
            int l;cin>>l;
            M[i][l]=1;
        }
    }
}
int d[N],f[N],t=1,n;
stack <int>S;
void dfs(){
    S.push(1);
    d[1]=t;
    while(S.empty()!=true){
        int flag=0,i=1;
        while(flag==0 && i<=n){
            if(M[S.top()][i]==0){
                i++;
            }else{
                    flag++;
                for(int z=1;z<=n;z++) M[z][i]=0;
                
            }
        }
        t++;
        if(i>=n+1){
            f[S.top()]=t;
            S.pop();
        }else{
            S.push(i);
            d[i]=t;
        }
    }
}

int main(){
    cin>>n;
    graph(n);
    dfs();
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    
    return 0;
}

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;
}