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 <iostream>
using namespace std;

int n;
int v[100][100];
int d[100], f[100], r[100];

void stamp(int id, int t) {
	if (t > 2 * n)
		return;

	if (d[id - 1] == 0) {
		d[id - 1] = t;
		int i = 0;
		while (v[id - 1][i] == 0)
			i++;
		if (i < n && d[i] == 0)
			stamp(i + 1, t + 1);
		else
			stamp(id, t + 1);
	}
	else if (f[id - 1] == 0) {
		int i;
		for(i = 0; i < n; i++)
			if (v[id - 1][i] == 1 && d[i] == 0) {
				stamp(i + 1, t);
				break;
			}
		if (i > n - 1) {
			f[id - 1] = t;
			int j1 = 0, ct = 0;
			for (int j = 0; j < n; j++){
				if (v[j][id - 1] == 1 && f[j] == 0 && d[j] != 0) {
					ct++;
					if(ct == 1 || d[j] == d[id - 1] - 1)
						j1 = j;
				}
			}
			if(j1 < n)
				stamp(j1 + 1, t + 1);

			int k = 0;
			while (d[k] != 0)
				k++;
			if (k < n)
				stamp(k + 1, t + 1);
		}
	}	
	return;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		d[i] = 0;
		f[i] = 0;
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			v[i][j] = 0;

	for (int i = 0; i < n; i++) {
		int u, k, s;

		cin >> u >> k;

		for (int j = 0; j < k; j++) {
			cin >> s;
			v[u - 1][s - 1] = 1;
		}
	}

	stamp(1, 1);

	for (int i = 0; i < n; i++)
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;

	return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

void dfs(const vvi& g, vector<bool>& seen, vi& d, vi& f, int& t, int v) {
    stack<int> st;
    st.push(v);
    d[v] = t++;
    seen[v] = true;

    while (!st.empty()) {
        int v = st.top();

        bool finished = true;
        for (auto itr = g[v].begin(); itr != g[v].end(); ++itr) {
            if (!seen[*itr]) {
                seen[*itr] = true;
                d[*itr] = t++;
                st.push(*itr);
                finished = false;
                break;
            }
        }

        if (finished) {
            st.pop();
            f[v] = t++;
        }
    }
}

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

    int n;
    cin >> n;

    vvi g(n);
    rep(i, 0, n) {
        int u, k;
        cin >> u >> k;

        rep(j, 0, k) {
            int v;
            cin >> v;
            g[u - 1].push_back(v - 1);
        }
    }

    int t = 1;

    vi d(n), f(n);
    vector<bool> seen(n, false);

    rep(i, 0, n) {
        if (!seen[i]) { dfs(g, seen, d, f, t, i); }
    }

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

    return 0;
}

C++: 
#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;


vector<int> G[105];
int d[105];
int f[105];
int tm = 1;
void dfs(int p){
    d[p]=tm;
    rep(i,G[p].size()){
        if(d[G[p][i]]==-1){
            tm++;
            dfs(G[p][i]);
        }
    }
    f[p] = ++tm;
    return;
}
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        d[i]=-1;
        f[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    dfs(1);
    for(int i = 1;i <= n;i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }
}

C++: #include <iostream>
#include <queue>
using namespace std;
 
void dfs(int cur);
int df[100][2]={};
bool dc[100]={};
bool adj[100][100]={};//初期化を忘れない
int n,u,v,k;
int t = 1;
queue<int> q;
 
int main(){
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> u >> k;
    for (int j=0; j<k; j++){
      cin >> v;
      adj[u-1][v-1] = true;
    }
  }
   
  //探索は一回で終わるとは限らない　グラフは非連結の場合もある？
  for (int i=0; i<n; i++){
    if (dc[i] != true)
      dfs(i);
  }
   
   
  for (int i=0; i<n; i++)
    cout << i+1 << " " << df[i][0] << " " << df[i][1] << endl;
 
}
 
void dfs(int cur){
  dc[cur] = true;
  df[cur][0] = t;
  t += 1;
  for (int i=0; i<n; i++){
    if (adj[cur][i] && !dc[i]){
      dfs(i);
    }
  }
  df[cur][1] = t; 
  t += 1;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
bool g[110][110];
int d[110];
int f[110];
int current;

void dfs1(int s)
{
	if (d[s] != -1) return;

	stack<int> stk;
	d[s] = ++current;
	stk.push(s);
	while (!stk.empty()) {
		int u = stk.top();
		int flag = 0;
		for (int j = 1; j <= n; j++) {
			if (g[u][j] && d[j] == -1) {
				flag = 1;
				stk.push(j);
				d[j] = ++current;
				break;
			}
		}

		if (flag == 0) {
			f[u] = ++current;
			stk.pop();
		}

	}
}

void dfs()
{
	for (int i = 1; i <= n; i++)
		dfs1(i);

}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		int u, k, v;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			g[u][v] = true;
		}
	}

	for (int i = 1; i <= n; i++) {
		d[i] = -1;
		f[i] = -1;
	}

	dfs();

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

	return 0;
}