Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

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