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 <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }

template<class T>
class DirectedGraph {
public:
	class Edge {
	public:
		int to;
		T cost;

		Edge(int t, T c) : to(t), cost(c) {}

		bool operator<(const Edge& right) const {
			return cost == right.cost ? to < right.to : cost < right.cost;
		}
	};

	vector<vector<Edge>> G;
	int V;

	DirectedGraph(int n = 0) {
		resize(n);
	}

	void resize(int n) {
		V = n;
		G.resize(n);
	}

	void addEdge(int from, int to, T cost = NULL) {
		int v = max(from, to);
		if (v >= V)
			resize(v + 1);
		G[from].push_back(Edge(to, cost));
	}


	int t = 1;
	vector<pii> stamp;
	vector<bool> visit;
	void dfs(int s) {
		visit.resize(V);
		stamp.resize(V);
		calcDfs(s);
	}

	void calcDfs(int s) {
		if (visit[s])
			return;

		stamp[s].first = t++;

		visit[s] = true;
		for (int i = 0; i < G[s].size(); ++i) {
			calcDfs(G[s][i].to);
		}

		stamp[s].second = t++;
	}

	vector<int> bfs() {

	}
};

int main() {
	DirectedGraph<int> g;
	int n, id, k, to;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> id >> k;
		while (k--) {
			cin >> to;
			g.addEdge(id, to);
		}
	}

	for (int i = 1; i <= n; ++i)
		g.dfs(i);

	for (int i = 1; i <= n; ++i) {
		printf("%d %d %d\n", i, g.stamp[i].first, g.stamp[i].second);
	}

	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
static const int N=101;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int M[N][N]={0};
int n;
int color[N]={WHITE},one[N],two[N];
int tt=0,aaa[N]={1};

int next(int num){
    for(int i=aaa[num];i<=n;i++){
        aaa[num]=i+1;
        if(M[num][i]) return i;
    }
    return -1;
}

void dfs_visit(int r){
    stack<int> S;
    S.push(r);
    color[r]=GRAY;
    one[r]=++tt;
    
    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1){
            if(color[v]==WHITE){
                color[v]=GRAY;
                one[v]=++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u]=BLACK;
            two[u]=++tt;
        }
    }
}

void dfs(){
    for(int i=1;i<=n;i++){
        if(color[i]==WHITE) dfs_visit(i);
    }
    for(int i=1;i<=n;i++){
        cout << i << " " << one[i] << " " << two[i] << endl;
    }
}




int main(void){
    cin >> n;
    for(int i=0;i<n;i++){
        int u,k;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            int v;
            cin >> v;
            M[u][v]=1;
        }
    }
    
    dfs();

    return 0;
}

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int t = 0;
int n;

void dfs_v(v2& a, v2& b, int p){
	p--;
	if(a.at(p).at(0) == -1){
		return;
	}
	b.at(p).push_back(++t);
	a.at(p).at(0) = -1;
	rep(i, a.at(p).at(1)){
		int np = a.at(p).at(2+i);
		dfs_v(a, b, np);
	}
	b.at(p).push_back(++t);
}
void dfs(v2& a, v2& b){
	rep(i, n){
		if(a[i][0] != -1){
			dfs_v(a, b, a[i][0]);
		}
	}
}

int main(){
	cin >> n;
	v2 a(n, v1(0));
	v2 b(n, v1(0));
	rep(i, n){
		int m;
		cin >>m;
		a[i].push_back(m);
		b[i].push_back(m);
		int x;
		cin >> x;
		a.at(i).push_back(x);
		rep(j, x){
			int y;
			cin >> y;
			a.at(i).push_back(y);
		}
	}
	dfs(a, b);
	rep(i, n){
		rep(j, 3){
			cout << b[i][j];
			if(j != 2) cout << " ";
			else cout << endl;
		}
	}
}

C++: #include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN = (int)1e2 + 10;

int n;
vector<int> g[MAXN];
int vis[MAXN];
int st[MAXN],en[MAXN];
int clk;

void DFS(int u){
    vis[u]=1;
    st[u]=++clk;
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(vis[v]) continue;
        DFS(v);
    }
    en[u]=++clk;
}

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int u,k; scanf("%d%d",&u,&k);
        while(k--){
            int v; scanf("%d",&v);
            g[u].push_back(v);
        }
        sort(g[u].begin(),g[u].end());
    }
    for(int i=1;i<=n;i++)if(!vis[i]) DFS(i);
    for(int i=1;i<=n;i++) printf("%d %d %d\n",i,st[i],en[i]);
}

int main(){
    work();
    return 0;
}