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<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vb=vector<bool>;
using pii=pair<int,int>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
vi conne[100];
vb is_visited(100,false);
int n;
int t=1;;
int f[100];
int d[100];
void dfs(int i){
    if(!is_visited[i]){
        d[i]=t++;
        is_visited[i]=true;
    }
    for(int itr:conne[i]){
       if(is_visited[itr])continue;
       dfs(itr);
    }
    f[i]=t++;
}
int main( ){
    cin>>n;
    rep(i,0,n){
        int id;
        cin>>id;
        id--;
        int num; cin>>num;
        rep(j,0,num){
            int in; cin>>in;
            in--;
            conne[id].push_back(in);
        }
        sort(conne[id].begin(),conne[id].end());
    }
    rep(i,0,n){
        if(is_visited[i]==false)dfs(i);
    }
    rep(i,0,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
#define MAX 101
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, t, top, u[MAX], color[MAX], M[MAX][MAX], S[MAX], d[MAX], f[MAX];

int next(int u){
  for(int i=1; i<=n; i++){
    if(M[u][i] == 1 && color[i] == WHITE){
      return i;
    }
  }
  return NIL;
}

void dfs(int u){
  int v;
  S[++top] = u;
  color[u] = GRAY;
  d[u] = ++t;

  while(top > 0){
    u = S[top];
    v = next(u);
    if(v != NIL){
      color[v] = GRAY;
      d[v] = ++t;
      S[++top] = v;
    }else{
      top--;
      color[u] = BLACK;
      f[u] = ++t;
    }
  }
}

void dfs_init(){
  for(int i=0; i<MAX; i++){
    color[u[i]] = WHITE;
  }

  t = 0;
  top = 0;
}

int main(void){
  int k, m;
  cin >> n;

  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      M[i][j] = 0;
    }
  }

  for(int i=0; i<n; i++){
    cin >> u[i] >> k;
    for(int j=0; j<k; j++){
      cin >> m;
      M[u[i]][m] = 1;
    }
  }

  dfs_init();
  for(int i=0; i<n; i++){
    if(d[u[i]] == 0) dfs(u[i]);
  }

  for(int i=0; i<n; i++){
    cout << u[i] << " " << d[u[i]] << " " << f[u[i]] << endl; 
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,step=0,fdepth[105],sdepth[105];
bool visit[105],c[105][105];
void dfs(int node){
    step++;
    fdepth[node]=step;
    for(int i=1;i<=n;i++)
        if(!visit[i]&&c[node][i]){
            visit[i]=1;
            dfs(i);
        }
    step++;
    sdepth[node]=step;
}
int main(){
    ios_base::sync_with_stdio(0);
    //cin.tie(0);
    while(cin>>n){
        memset(fdepth,0,sizeof(fdepth));
        memset(sdepth,0,sizeof(sdepth));
        memset(c,0,sizeof(c));
        memset(visit,0,sizeof(visit));
        int parent,num,son;
        step=0;
        for(int i=0;i<n;i++){
            cin>>parent>>num;
            while(num--){
                cin>>son;
                c[parent][son]=1;
            }
        }
        visit[1]=1;
        dfs(1);
        for(int i=1;i<=n;i++)
            cout<<i<<' '<<fdepth[i]<<' '<<sdepth[i]<<'\n';
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
using namespace std;

#define MAX 100

int d[MAX], f[MAX], t = 0, M[MAX][MAX] = {}, n;

void dfs(){
    int seen[MAX] = {};
    rep(i, n){
        if(seen[i]) continue;
        stack<int> todo;
        seen[i] = 1;
        todo.push(i);
        t++;
        d[i] = t;
        while(!todo.empty()){
            int m = todo.top();
            rep(j, n + 1){
                if(j == n){
                    todo.pop();
                    t++;
                    f[m] = t;
                    break;
                }
                if(M[m][j] && !seen[j]){
                    todo.push(j);
                    t++;
                    d[j] = t;
                    seen[j] = 1;
                    break;
                }
            }
        }
    }
}

int main(){
    cin >> n;
    rep(i, n){
        int l, p;
        cin >> l >> p;
        rep(j, p){
            int q;
            cin >> q;
            M[l - 1][q - 1] = 1;
        }
    }
    dfs();
    
    rep(i, n){
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
    
    return 0;
}