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 d[101] = {},f[101];
int a[101][101];
int kosu[101];
int joutai = 0;
void dfs(int x){
	joutai++;
	d[x] = joutai;
	for(int i = 1;i <= kosu[x];i++){
		if(d[a[x][i]] == 0){
			dfs(a[x][i]);
		}
	}
	joutai++;
	f[x] = joutai;
}

int main(){
	int n,x;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> x;
		cin >> kosu[x];
		for(int j = 1;j <= kosu[x];j++){
			cin >> a[x][j];
		}
	}
	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 <iostream>
#include <ios>
#include <vector>
using namespace std;

void read_data(int n, vector<vector<int>> & Es){
    int u = 0, k = 0, v = 0;
    while (n--){
        cin >> u;
        cin >> k;
        while (k--){
            cin >> v;
            Es[u - 1].push_back(v - 1);
        }
    }
}

void display_result(int n, vector<int> & d, vector<int> & f){
    for (int i = 0; i != n; ++i){
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

void dfs(int node, int & time, vector<vector<int>> & Es, vector<int> & d, vector<int> & f ){
    if (d[node]) return;
    d[node] = time;
    ++time;
    for (auto next_node : Es[node]){
        dfs(next_node, time, Es, d, f);
    }
    f[node] = time;
    ++time;
}

int main()
{
    int n = 0;
    cin >> n;
    vector< vector<int> > Es(n);
    vector<int> d(n, 0);
    vector<int> f(n, 0);
    read_data(n, Es);
    int node = 0;
    int time = 1;
    dfs(node, time, Es, d, f);
    display_result(n, d, f);
    
    return 0;
}

C++: #include <iostream>
#include <queue>

using namespace std;

int G[100][100];
int In[100];
int Out[100];
void init() {
	for (int i = 0; i < 100; i++) {
		for(int j = 0; j < 100; j++)
			G[i][j] = 0;
		In[i] = -1;
		Out[i] = -1;
	}	
}

void dfs(int src);

int main() {
	init();
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v_j;
			cin >> v_j;
			G[u - 1][v_j - 1] = 1;
		}
	}
	dfs(0);
	for (int i = 0; i < n; i++)
		cout << i + 1 << " " << In[i] << " " << Out[i] << endl;
}

int time = 1;

void dfs(int cur) {
	In[cur] = time;
	time++;
	for (int dst = 0; dst < 100; dst++)
		if (G[cur][dst] == 1 && In[dst] == -1)
			dfs(dst);
	Out[cur] = time;
	time++;
}

C++: #include <iostream>
#include <vector>
#include <cstring>

using namespace std;

int n, u, k, v, d[110], f[110], time=0;
bool vis[110];
vector<int> adj[110];

void dfs (int p)
{
    time++;
    vis[p]=true;
    d[p]=time;
    for (auto u : adj[p])
    {
        if (!vis[u]) dfs(u);
    }
    time++;
    f[p]=time;
}

int main()
{
    memset(vis, false, sizeof(vis));
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>u>>k;
        for (int j=0; j<k; j++)
        {
            cin>>v;
            adj[u].push_back(v);
        }
    }
    dfs(1);
    for (int i=1; i<=n; i++)
    {
        cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
    }
    return 0;
}

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

typedef long long ll;
#define inf 1e9+7

int f[200],d[200];
bool table[200][200];
int cou;

void init(){
    for(int i=0;i<200;i++){
        f[i]=d[i]=-1;
    }
}

void dfs(int n,int itr){
    cou++;
    if(d[itr]<0)d[itr]=cou;
    for(int i=0;i<n;i++){
        if(d[i]<0&&table[itr][i]) dfs(n,i);
    }
    cou++;
    f[itr] = cou;
}

void solve(int n){
    for(int i=0;i<n;i++){
        if(d[i]<0)dfs(n,i);
    }
}

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


    init();
    int u,k,v;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> u >> k;
        for(int j=0;j<k;j++){
            cin >> v;
            table[u-1][v-1]=true;
        }
    }

    solve(n);

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

    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <climits>
#include <stack>

using namespace std;

int main() {
	stack<int> S;

	int n;
	int u, v;
	int AdjList[101][99];
	int next[101];
	int Deg[101];
	bool Visited[101];
	int d[101], f[101], time;
	int i, j;
	cin >> n;
	for (i = 1; i <= n; i++) {
		Visited[i] = false;
		next[i] = 0;
		d[i] = 0;
		cin >> u;
		cin >> Deg[u];
		for (j = 0; j < Deg[u]; j++) {
			cin >> v;
			AdjList[u][j] = v;
		}
	}

	time = 1;
	for (i = 1; i <= n; i++) {
		if (Visited[i] != true) {
			v = i;
			S.push(v);
			while (S.empty() != true) {
				v = S.top();
				if (d[v] == 0) {
					d[v] = time++;
				}
				Visited[v] = true;
				for (i = next[v]; i < Deg[v]; i++) {
					u = AdjList[v][i];
					if (Visited[u] != true) {
						S.push(u);
						break;
					}
				}
				if (i == Deg[v]) {
					S.pop();
					f[v] = time++;
				}
				else {
					next[v] = i + 1;
				}
			}
		}
	}

	for (i = 1; i <= n; i++) {
		printf("%d %d %d\n", i, d[i], f[i]);
	}

	return 0;

}