Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

C++: #include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <vector>
#define MAX 10010
#define rep(i,p) for(int i=0;i<p;i++)
#define pb push_back
using namespace std;
int n,hoge,foo,visit_time=1;
int graph[MAX][MAX] = {0};
int d[MAX]; // ????????????
int f[MAX]; // ??£??\????????????????????????

void dfs (int cur) {
  // visiting cur
  d[cur] = visit_time;
  visit_time++;

  rep(dst,n) {
    if (graph[cur][dst] == 1 && d[dst] == -1) dfs(dst);
  }
  f[cur] = visit_time;
  visit_time++;
}

int main(){
  cin >> n;
  rep(i,n) {
    d[i] = -1;
    f[i] = -1;
  }
  rep(i,n) {
    cin >> hoge >> foo;
    rep(j,foo) {
      cin >> hoge;
      graph[i][hoge-1] = 1;
    }
  }
  rep(i,n) if (d[i] == -1) dfs(i);
  rep(i,n) cout << i+1 << " " << d[i] << " " << f[i] << endl;
  return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u) {
    for(int v=nt[u]; v<n; v++) {
        nt[u] = v + 1;
        if(M[u][v]) {
            return v;
        }
    }

    return -1;
}

void dfs_visit(int r) {
    for(int i=0; i<n; i++) {
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!S.empty()) {
        int u = S.top();
        int v = next(u);
        if(v!=-1) {
            if(color[v]==WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }
        else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs() {
    for(int i=0; i<n; i++) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    for(int u = 0; u<n; u++) {
        if(color[u]==WHITE) {
            dfs_visit(u);
        }
    }
    for(int i=0; i<n; i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int u, k, v;

    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 >> k;
        u--;
        for(int j=0; j<k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}

C++: #if 0
time: 15min
using e[] as a indicator to find whether a node has been searched.						
#endif
#include <iostream>
#include <queue>

using namespace std;

int p[100+10][100+10];
int D[100+10],e[100+10],f[100+10];
int n,a,b,c,t;

void dfs(int cur){
	D[cur] = 1;
	t += 1;
	for (int i=1; i<=n; i++){
		if (p[cur][i]>0 && !D[i]){
			f[i] = t+1;
			dfs(i);
		}
	}
	t += 1;
	e[cur] = t;
}

int main(){
	cin >> n;
	for (int i=1; i<=n; i++){
		cin >> a >> b;
		for (int j=1; j<=b; j++){
			cin >> c;
			p[a][c] = 1;
		}
	}
	f[1] = 1;
	for (int i=1; i<=n; i++){
		if (!D[i]){
			f[i] = !f[i] ? t+1 : f[i];
			dfs(i);
		} 	
	}
	

	for (int i=1; i<=n; i++){
		cout << i << ' ' << f[i] << ' ' << e[i] << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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;
}
void dfs(ll v, const vvl &g,vector<bool> &seen,vl &fir,vl &last,ll &time){
    fir[v]=time++;
    seen[v]=true;
    for(auto nv:g[v]){
        if(seen[nv])continue;
        dfs(nv,g,seen,fir,last,time);
    }
    last[v]=time++;
}
int main(){
    ll n;cin >> n;
    vvl g(n);
    rep(i,n){
        ll x;cin >> x;x--;
        ll k;cin >> k;
        rep(j,k){
            ll y;cin >> y;y--;
            g[x].pb(y);
        }
    }
    vector<bool> seen(n,false);
    vl fir(n),last(n);
    ll time=1;
    ll x=0;
    while(x<n){
        dfs((ll)x,g,seen,fir,last,time);
        while(seen[x])x++;
    }
    rep(i,n)cout <<i+1<<" "<< fir[i]<< " "<<last[i] <<endl;
}