Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	g := graph{}
	g.ee = make([]Edges, n)
	g.visited = make([]bool, n)
	g.found = make([]int, n)
	g.leave = make([]int, n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner) - 1
		k := getNextInt(scanner)
		for j := 0; j < k; j++ {
			v := getNextInt(scanner) - 1
			g.ee[u] = append(g.ee[u], Edge{
				to: v,
				id: u,
			})
		}
	}
	for i := 0; i < n; i++ {
		sort.Sort(g.ee[i])
	}
	for i := 0; i < n; i++ {
		if g.visited[i] {
			continue
		}
		g.dfs(i)
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", i+1, g.found[i], g.leave[i]))
	}
}

// Edge ...
type Edge struct {
	to, id int
}

type Edges []Edge

func (a Edges) Len() int           { return len(a) }
func (a Edges) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Edges) Less(i, j int) bool { return a[i].id < a[j].id }

type graph struct {
	ee           []Edges
	t            int
	n            int
	visited      []bool
	found, leave []int
}

func (g *graph) dfs(i int) {
	g.visited[i] = true
	g.t++
	g.found[i] = g.t
	for _, e := range g.ee[i] {
		if g.visited[e.to] {
			continue
		}
		g.dfs(e.to)
	}
	g.t++
	g.leave[i] = g.t
}

C++: #include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
int n,tim=0;
vector<vector<int> >  lis(100000+5);
vint d(100000+5); vint f(100000+5); vector<bool> flag(100000+5);
void dfs(int now){
    if(flag[now]){
        return;
    }
    flag[now]=true;
    d[now]=++tim;
    rep(i,lis[now].size()){
        dfs(lis[now][i]);
    }
    f[now]=++tim;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    int u,k,v;
    rep(i,n){
        cin>>u>>k;
        rep(j,k){
            cin>>v;
            lis[u].push_back(v);
        }
    }
    REP(i,1,n+1){
        if(!flag[i]){
            dfs(i);
        }
    }    
    REP(i,1,n+1){
        cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
    }
    return(0);
}

C++: #include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int a[101][101],start[101],end[101],n,p=0;
void dfs(int u){
	start[u]=++p;
	r(i,1,n+1)if(a[u][i])dfs(i);
	end[u]=++p;
}
int main(){
	int q,qq,qqq;
	cin>>n;
	r(i,0,n){cin>>q>>qq;
		r(i,0,qq){cin>>qqq;
			a[q][qqq]++;
		}
	}
	dfs(1);
	r(i,1,n+1)cout<<i<<' '<<start[i]<<' '<<end[i]<<endl;
}

C++: #include<bits/stdc++.h>
using namespace std;

vector<bool> seen;
vector<int> first_order;
vector<int> last_order;

void dfs(vector<vector<int>> &G, int v, int& ptr) {
    first_order[v] = ptr++;

    seen[v] = true;
    for(auto next_v : G[v]){
        if(seen[next_v]) continue;
        dfs(G, next_v, ptr);
    }

    last_order[v] = ptr++;
}

int main(){
    int n;
    cin >> n;
    int u;
    int k;
    vector<vector<int>> G(n);
    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++)
        {
            int a; cin >> a;
            a--;
            G[u].push_back(a);
        }
    }
    
    seen.assign(n, false);
    first_order.resize(n);
    last_order.resize(n);
    int ptr = 1;
    for(int i = 0; i < n; i ++){
        if(!seen[i]) dfs(G, i, ptr);
    }

    for (int v = 0; v < n; v++)
        cout << v + 1 << " " << first_order[v] << " " << last_order[v] << endl;
}

C++: #include <iostream>
#include <vector>
using namespace std;

vector<vector<int>> G;
vector<int> used;
vector<int> found;
vector<int> done;

int dfs(int v, int t){
    if(used[v]){
        return done[v];
    }
    else{
        used[v] = 1;
        found[v] = t;
    }
    for(long long i=0; i<G[v].size(); i++){
        int nv = G[v][i];
        if(used[nv]) continue;
        else{
            t = dfs(nv, ++t);
        }
    }
    return done[v] = ++t;
}

int main(){
    int N; cin>>N;
    G.resize(N);
    used.resize(N, 0);
    found.resize(N, 0);
    done.resize(N, 0);
    found[0] = 1;
    for(long long i=0; i<N; i++){
        int u, k; cin >> u >>k;
        u--;
        G[u].resize(k);
        for(long long j=0; j<k; j++){
            int v; cin >> v;
            v--;
            G[u][j] = v;
        }
    }
    int t = 1;
    for(long long i=0; i<N; i++){
        if(used[i]) continue;
        t = dfs(i, t) + 1;
    }
    for(long long i=0; i<N; i++){
        cout << i+1 << " " << found[i] << " " << done[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

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

//uに隣接するvを番号順に取得
int next(int u) {
    for(int v = nt[u]; v < n; v++) {
        nt[u] = v+1;
        if(M[u][v]) {
            return v;
        }
    }

    return -1;
}

//スタックを用いたDFS
void dfs_visit(int r) {
    rep(i, n) {
        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() {
    rep(i, n) {
        color[i] = WHITE;
        nt[i] = 0;
    }

    tt = 0;

    //未訪問のuを始点としてDFS
    rep(u, n) {
        if(color[u] == WHITE) {
            dfs_visit(u);
        }
    }
    rep(i, n) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

    cin >> n;
    rep(i, n) {
        rep(j, n) {
            M[i][j] = 0;
        }
    }

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

    dfs();
    
    return 0;
}