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>
//#define int long long
//#define _DEBUG
#include <vector>
using namespace std;
int const infty = -1, none = -9;

//input
int N, T[107][107]; //T[i][j]:i->T[i][j]の辺

int /*D[107], */t, d[107], f[107];
bool visited[107];
void dfs(int cur){
    visited[cur] = true;
    d[cur] = t;
    t++;
    //cerr << "Visiting " << cur << " " << t << endl;
    for(int j=0; j<107; j++){
        if(T[cur][j]==none) break;
        if(!visited[T[cur][j]]/* || (D[T[cur][j]]!=infty || D[T[cur][j]]>D[cur])*/){
            //D[T[cur][j]] = D[cur]+1;
            dfs(T[cur][j]);
        }
    }
    f[cur] = t;
    t++;
}
void solve(){
    t = 1;
    //D[0] = 0;
    for(int i=0; i<N; i++){
        if(!visited[i]) dfs(i);
    }
}
void get(){
    cin >> N;
    //fill(D, D+N, infty);
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            T[i][j] = none;
        }
    }

    for(int i=0; i<N; i++){
        int _i, k;
        cin >> _i >> k;
        for(int j=0; j<k; j++){
            int vj;
            cin >> vj;
            T[i][j] = vj-1;
        }
    }
    fill(visited, visited+N, false);
}

signed main(){
    get();
    solve();
    /*for(int i=0; i<N; i++){
        cout << i+1 << " " << D[i] << endl;
    }*/
    for(int i=0; i<N; i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

using namespace std;

struct Node {
    bool visit = false;
    vector<int> next;
    int position = 0;
    int start;
    int end;
};

int main() {
    int n, id, k, temp, time = 1;
    Node node[101];
    stack<int> st;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            cin >> temp;
            node[id].next.push_back(temp);
        }
    }

    node[1].start = time++;
    st.push(1);
    while (!st.empty()) {
        temp = st.top();
        if (node[temp].position < node[temp].next.size() && node[node[temp].next[node[temp].position]].visit == false) {
            node[node[temp].next[node[temp].position]].start = time++;
            st.push(node[temp].next[node[temp].position++]);
        }
        else {
            node[temp].visit = true;
            node[temp].end = time++;
            st.pop();
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << node[i].start << " " << node[i].end << endl;
    }

    return 0;
}

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

int discover(int &t, int node, int n, vector<vector<int>> &g, vector<int> &d, vector<int> &f);

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

	vector<int> d(n+1);
	vector<int> f(n+1);
	stack<int> st;

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


	int t=0;
	for (int i=1;i<=n;++i)
	{
		if (d[i]<0)
		{
			d[i]=++t;
			discover(t,i,n,g,d,f);
			//f[i]=++t;
		}
	}

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


int discover(int &t, int node, int n, vector<vector<int>> &g, vector<int> &d, vector<int> &f)
{

	for (int i=0;i<g[node].size();++i)
	{
		int nn=g[node][i];
		if (d[nn]<0)
		{
			++t;
			d[nn]=t;
			discover(t,nn,n,g,d,f);
		}
	}

	++t;
	f[node]=t;

	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define MAX 2000000000
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std ;

int d[102] = { 0 }, f[102] = { 0 };
int M[102][102];

int main() {
	stack<int> stk;
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++) {
		int k,l,m;
		cin >> m;
		cin >> k;
		for (int j = 0;j < k;j++) {
			cin >> l;
			M[m][l] = 1;
		}
	}
    
	stk.push(1);

    int i = 1,time=1;
    d[1]=1;
	while (!stk.empty()) {
		if (M[stk.top()][i] == 1 && d[i] == 0) {
			stk.push(i);
			time++;
			d[i] = time;
			i = 1;
		}
		else {
			i++;
			if (i > n) {
			    time++;
				f[stk.top()] = time;
				stk.pop();
				i=1;
			}
		}
	}

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

C++: #include<iostream>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
using namespace std;
int G[100][100] = {};
int time = 0;
typedef struct ANS
{
	int id, t, e;
	bool done;
};

void rec(ANS a[],int t)
{
	::time++;
	a[t].t = ::time;
	a[t].done = true;
	FOR(i, 0, 100)
	{
		if (G[t][i] == 1 && a[i].done == false)
		{
			rec(a, i);
		}
	}
	::time++;
	a[t].e = ::time;
}

int main()
{
	ANS ans[101];
	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		ans[i].id = i + 1;
		ans[i].done = false;
		int u, m;
		cin >> u >> m;
		FOR(j, 0, m)
		{
			int l;
			cin >> l;
			G[u - 1][l - 1] = 1;
		}
	}
	rec(ans, 0);
	FOR(i, 0, n)
	{
		cout << ans[i].id << " " << ans[i].t << " " << ans[i].e << endl;
	}
	return 0;
}