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 "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<LL, LL>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<LL>;

//==============================================
int n, tt = 0;
vvi M;
vi D, F, searchStatus;

// ??±???????????¢?´¢
void antDfs(int u) {
	searchStatus[u] = 1;

	// ?????????(??????)??????????????????
	D[u] = ++tt;
	REP3(i, 1, n) {
		if (M[u][i] == 0) continue;

		if (searchStatus[i] == -1) {
			antDfs(i);
		}
	}
	// ?????????(??????)???????????????
	F[u] = ++tt;

	// ??¢?´¢??????
	searchStatus[u] = 1;
}

void print() {
	REP3(i, 1, n) {
		cout << i << " " << D[i] << " " << F[i] << "\n";
	}
}

void solve() {

	REP3(i, 1, n) {
		if (searchStatus[i] == -1) {
			//????¨???????i????§??????¨????????±???????????¢?´¢?????????
			antDfs(i);
		}
	}

	// ??????
	print();
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	
	M.resize(n + 1, vi(n + 1));
	D.resize(n + 1);
	F.resize(n + 1);

	// ??¢?´¢??¶??????????????? (?????¢?´¢)
	searchStatus.resize(n + 1, -1);

	
	int u, k, v;
	REP3(i, 1, n) {
		cin >> u >> k;
		REP3(j, 1, k) {
			cin >> v;
			M[u][v] = 1;
		}
	}

	solve();
	return 0;
}

C++: #include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
vll d(100),f(100);
ll t=0;
void dfs(vvll g,vb &v,ll x){
  v[x]=true;
  d[x]=++t;
  
  rep(i,0,g[x].size()){
    if(!v[g[x][i]]){
      dfs(g,v,g[x][i]);
    }
  }
  f[x]=++t;
  
}
int main(){
  ll n;cin>>n;
  vvll g(n,vll(0));
  vb visited(n,false);
  rep(i,0,n){
    ll m,k;cin>>m>>k;
    m--;
    rep(j,0,k){
      ll x;cin>>x;
      g[m].push_back(--x);
    }
  }
  rep(i,0,n){
    if(!visited[i]){
      dfs(g,visited,i);
    }
  }
  
  rep(i,0,n){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  }
}

C++: 
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cstring>
#include <stack>
#define fre freopen("//home//yanjiewei//CLionProjects//cin.txt", "r", stdin)


using namespace std;

int map[105][105], vis[105];
stack <int> s;

int main(){
//    fre;
    memset(map, 0, sizeof(map));
    memset(vis, 0, sizeof(vis));
    int n;
    cin>> n;
    int u, k, v;
    for(int i = 0; i < n; i++){
        cin>> u;
        cin>> k;
        while(k--){
            cin>> v;
            map[u][v] = 1;
        }
    }
    int t = 1, now = 1;
    int d[105], f[105];
    s.push(1), d[1] = t, vis[1] = 1;
    while(!s.empty()){
        int p = 0;
        now = s.top();
        for(int i = 1; i <= n; i++){
            if(map[now][i] == 1 && vis[i] == 0) {
                s.push(i);
                t++, d[i] = t;
                vis[i] = 1;
                p++;
                break;
            }
        }
        if(p == 0){
            int out = s.top();
            s.pop();
            t++, f[out] = t;
        }
    }
    for(int i = 1; i <= n; i++){
        cout<< i<< ' '<< d[i]<< ' '<< f[i]<< endl;
    }
    return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define INF 1000000007
typedef int64_t in;
typedef long long ll;

int n;
int m[105][105] = {};
int color[105] = {};
int d[105] = {};
int f[105] = {};
int u,k;
int v;
int t=0;
int nt[105] = {};

int next(int u){
    REP(v, nt[u], n){
        nt[u] = v + 1;
        if(m[u][v]) return v;
    }
    return -1;
}

void dfs(int u){
    rep(u,n){
        if(color[u] == 0){
            stack<int> S;
            color[u] = 1;
            d[u] = ++t;
            S.push(u);

            while(!S.empty()){
                u = S.top();
                v = next(u);
                if(v != -1){
                    if(color[v] == 0){
                        S.push(v);
                        color[v] = 1;
                        d[v] = ++t;
                    }
                }else{
                    S.pop();
                    color[u] = 2;
                    f[u] = ++t;
                }
                
            }
        }
    }

    rep(i,n){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main(){
    cin >> n;
    
    /*rep(i,n){
        color[i] = 0;
    }*/

    rep(i,n){
        cin >> u >> k;
        for(int i=0; i<k; i++){
            cin >> v;
            m[u-1][v-1] = 1;
        }
    }

    dfs(0);
}