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>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int n, t = 0;
vector<vector<int> > G(110);
pair<int, int> toki[110];
bool vis[110];

void dfs(int v)
{
    if(vis[v]) return;
    t++;
    toki[v].first = t;
    vis[v] = true;
    rep(i, G[v].size())
    {
        if(vis[G[v][i]]) continue;
        dfs(G[v][i]);
    }
    t++;
    toki[v].second = t;
    return;
}

int main(void)
{
    cin >> n;
    rep(i, n) vis[i] = false;
    rep(i, n)
    {
        int t, k;
        cin >> t >> k;
        t--;
        rep(j, k)
        {
            int v;
            cin >> v;
            v--;
            G[t].push_back(v);
        }
    }
    rep(i, n)
    {
        dfs(i);
    } 
    rep(i, n)
    {
        cout << i+1 << " " << toki[i].first << " " << toki[i].second << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
int d[101],f[101],G[101][101];
stack<int>s;
int n,t;
void dfs(int u)
{
    s.push(u);
    d[u]=t++;
    int i;
    while(!s.empty()){
        u=s.top();
        for(i=1;i<=n;i++)
        {
            if(G[u][i]==1 && d[i]==0)
            {
                s.push(i);
                d[i]=t++;
                //u=i;
                break;
            }
        }
        if(i>n)
        {
            f[s.top()]=t++;
            s.pop();
        }
    }
}
int main()
{
    int k,u,v;
    cin>>n;
    for(int i=1;i<=n;i++){
        d[i]=0;
        for(int j=1;j<=n;j++)
            G[i][j]=0;
    }
    for(int i=0;i<n;i++)
    {
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            cin>>v;
            G[u][v]=1;
        }
    }
    t=1;
    for(int i=1;i<=n;i++)
    {
        if(d[i]==0)
            dfs(i);
    }
    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, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    Graph g(n);
    REP(i, n) {
        ll u, k;
        cin >> u >> k;
        u--;
        REP(j, k) {
            ll v;
            cin >> v;
            v--;
            add_edge(g, u, v, 1, false, 1);
        }
    }

    Array d(n, 0);
    Array f(n, 0);
    int id = 1;
    auto dfs = [&](auto &&self, int v) -> void {
        d[v] = id;
        id++;
        for(auto e : g[v]) {
            if(d[e.to])
                continue;
            self(self, e.to);
        }
        f[v] = id;
        id++;
    };
    REP(i, n) {
        if(d[i])
            continue;
        dfs(dfs, i);
    }
    REP(i, n) {
        cout << i + 1 << " " << d[i] << " " << f[i] << en;
    }
}

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

    solve();

    /*
    ll t;
    cin >> t;
    REP(i, t) { solve();}
    */

    return 0;
}