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 int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;
const int INF = 1e18;

struct edge
{
    int to;
    int cost;
};
using Graph = vector<vector<edge>>;

#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
Graph G;

int seen[110];
int discover[110];
int finish[110];
int stamp = 0;

void dfs(int cur)
{
    discover[cur] = stamp++;

    seen[cur] = BLACK;
    for (auto ne : G[cur])
    {
        int v = ne.to;
        int vc = ne.cost;
        if (seen[v] == BLACK)
            continue;
        dfs(v);
    }

    finish[cur] = stamp++;
}

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    G.resize(n + 1);

    for (int i = 0; i <= n; i++)
    {
        if (i == 0)
        {
            for (int j = 1; j <= n; j++)
            {
                G[0].push_back((edge){j, 1});
            }
        }
        else
        {
            int u, k;
            cin >> u >> k;
            for (int j = 0; j < k; j++)
            {
                int v;
                cin >> v;
                G[u].push_back((edge){v, 1});
            }
        }
    }

    for (int i = 0; i < 110; i++)
    {
        seen[i] = WHITE;
        discover[i] = INF;
        finish[i] = INF;
    }

    dfs(0);

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

signed main()
{
    solve();
    return 0;
}

C++: #include <iostream>
using namespace std;

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

void stamp(int id) {
//	if (t > 2 * n)
//		return;
	
	if (d[id - 1] == 0) {
		d[id - 1] = t;
		t++;
		int i = 0;
		while (v[id - 1][i] == 0)
			i++;
		if (i < n && d[i] == 0)
			stamp(i + 1);
		else
			stamp(id);
	}
	else if (f[id - 1] == 0) {
		int i;
		for(i = n - 1; i > -1; i--)
			if (v[id - 1][i] == 1 && d[i] == 0)
				stamp(i + 1);
		if (i < 0 && f[id - 1] == 0) {
			f[id - 1] = t;
			t++;
			for (i = n - 1; i > -1; i--)
				if (v[i][id - 1] == 1 && f[i] == 0)
					stamp(i + 1);
		}
	}
	else
		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;
		}
	}

	t = 1;
	stamp(1);

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

	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>

using namespace std;

int common_time=1,n;

int table[101][101],time_table[101][2];

void func(int node){
	if(time_table[node][0] == 0){
		time_table[node][0] = common_time++;
	}else{
		return;
	}
	for(int i=1;i<=n;i++){
		if(table[node][i] == 1){
			func(i);
		}
	}
	time_table[node][1] = common_time++;
}

int main(){
	int row,num,col;
	scanf("%d",&n);

	for(int i=1;i<=n;i++){
		for(int k=1;k<=n;k++){
			table[i][k]=0;
		}
		time_table[i][0]=0;
		time_table[i][1]=0;
	}

	for(int i=1;i<=n;i++){
		scanf("%d %d",&row,&num);
		for(int k=1;k<=num;k++){
			scanf("%d",&col);
			table[row][col]=1;
		}
	}

	for(int i=1;i<=n;i++){
		func(i);
	}

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

    return 0;
}

C++: #include <iostream>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

using namespace std;

int n, t = 0;
int color[MAX+1];
int m[MAX+1][MAX+1];
int d[MAX+1], f[MAX+1];

void visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++t;
    for(v = 1; v <= n; v++){
        if(m[u][v] == 0) continue;
        if(color[v] == WHITE) visit(v);
    }
    color[u] = BLACK;
    f[u] = ++t;
}

void dfs(){
    int u, i;
    for(u = 1; u <= n; u++) color[u] = WHITE;
    for(u = 1; u <= n; u++){
        if(color[u] == WHITE) visit(u);
    }
}

int main(){
    int k, u, v, i, j;
    
    cin >> n;

    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++) m[i][j] = 0;
    }

    for(i = 1; i <= n; i++){
        cin >> u >> k;
        for(j = 1; j <= k; j++){
            cin >> v;
            m[u][v] = 1;
        }
    }

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

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

using namespace std;

vector<int> adja[101];
int d[101], f[101], cnt;

void dfs(int u) {
    d[u] = ++cnt;
    for (auto v : adja[u]) {
        if (d[v] > 0)
            continue;
        dfs(v);
    }
    f[u] = ++cnt;
}

int main() {
    int n, k, u;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        adja[u].resize(k);
        for (int j = 0; j < k; ++j) {
            cin >> adja[u][j];
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (d[i] == 0)
            dfs(i);
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}