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>
#include <vector>
using namespace std;

vector<vector<int>> G;
vector<int> used;
vector<int> found;
vector<int> done;

int dfs(int v, int t){
    if(!used[v]){
        used[v] = 1;
        found[v] = t;
    }
    for(long long i=0; i<G[v].size(); i++){
        int nv = G[v][i];
        if(used[nv]) continue;
        else{
            t = dfs(nv, ++t);
        }
    }
    return done[v] = ++t;
}

int main(){
    int N; cin>>N;
    G.resize(N);
    used.resize(N, 0);
    found.resize(N, 0);
    done.resize(N, 0);
    found[0] = 1;
    for(long long i=0; i<N; i++){
        int u, k; cin >> u >>k;
        u--;
        G[u].resize(k);
        for(long long j=0; j<k; j++){
            int v; cin >> v;
            v--;
            G[u][j] = v;
        }
    }
    dfs(0, 1);
    for(long long i=0; i<N; i++){
        cout << i+1 << " " << found[i] << " " << done[i] << endl;
    }
    return 0;
}

C++: /* ALDS1_11_B: Depth First Search */

#include <iostream>
#include <cstdio>
#include <vector>
using std::vector;

vector<int> *graph;
int elapsed = 1;

// Search the graph recursively by depth-first search.
void traverse(int id, int found[], int finished[]) {
    if (0 < found[id]) {
        return;
    }

    found[id] = elapsed++;
    vector<int> adjs = graph[id];
    for (int i = 0; i < adjs.size(); i++) {
        traverse(adjs[i], found, finished);
    }
    finished[id] = elapsed++;
}

int main() {
    int n_v;
    scanf("%d", &n_v);

    int max_v = n_v + 1;
    graph = new vector<int>[max_v];

    for (int i = 0; i < max_v; i++) {
        int id, n_adjs;
        scanf("%d %d", &id, &n_adjs);

        for (int j = 0; j < n_adjs; j++) {
            int adj_id;
            scanf("%d", &adj_id);
            graph[id].push_back(adj_id);
        }
    }

    int found[max_v];
    int finished[max_v];
    std::fill_n(found, max_v, 0);
    std::fill_n(finished, max_v, 0);

    for (int id = 1; id < max_v; id++) {
        traverse(id, found, finished);
    }

    for (int id = 1; id < max_v; id++) {
        printf("%d %d %d\n", id, found[id], finished[id]);
    }
    return 0;
}

C++: #include<algorithm>
#include<bitset>
#include<iostream>
#include<iomanip>
#include<set>
#include<string>
#include<math.h>

using namespace std;

class zahyo{
	public:
	int x;
	int y;
	zahyo(){
		x=0;
		y=0;
	}
	zahyo(int x_,int y_){
		x=x_;
		y=y_;
	}
	void print(){
		cout<<x<<" "<<y;
	}
	zahyo operator+(zahyo add){
		add.x=this->x+add.x;
		add.y=this->y+add.y;
		return add;
	}
	zahyo operator-(zahyo add){
		add.x=this->x-add.x;
		add.y=this->y-add.y;
		return add;
	}
	bool operator==(const zahyo add) const{
		if(add.x==this->x and add.y==this->y){return true;}
		else{return false;}
	}
	bool operator!=(const zahyo add) const{
		if(add.x==this->x or add.y==this->y){return false;}
		else{return true;}
	}
	bool operator<(const zahyo add) const{
		if(this->x<add.x){return true;}
		else if(this->x==add.x and this->y<add.y){return true;}
		else{return false;}
	}
	bool operator>(const zahyo add) const{
		if(this->x>add.x){return true;}
		else if(this->x==add.x and this->y>add.y){return true;}
		else{return false;}
	}
	void input(){
		cin>>x>>y;
	}
};

int n;
int counter=0;
int glaph[100][100]={{}};
int ans[100][2]={{}};
void depthsearch(int t){
	counter++;
	ans[t][0]=counter;
	for(int i=0;i<n;i++){
		if(glaph[t][i]==1 and ans[i][0]==0){
			depthsearch(i);
		}
	}
	counter++;
	ans[t][1]=counter;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int k;
		cin>>k;
		cin>>k;
		for(int j=0;j<k;j++){
			int l;
			cin>>l;
			l--;
			glaph[i][l]=1;
		}
	}
	for(int i=0;i<n;i++){
		if(ans[i][0]==0){
			depthsearch(i);
		}
	}
	for(int i=0;i<n;i++){
		cout<<(i+1)<<" "<<ans[i][0]<<" "<<ans[i][1]<<endl;
	}
}

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

using namespace std;

void dfs(vector<vector<int>>& graph, int vertex, vector<bool>& marked, vector<int>& d, vector<int>& f, int& time) {
    if (marked[vertex])
        return;
    marked[vertex] = true;
    d[vertex] = ++time;
    for (int x: graph[vertex])
        if (!marked[x])
            dfs(graph, x, marked, d, f, time);
    f[vertex] = ++time;
}

int main() {
    int n;
    cin >> n;

    vector<vector<int>> graph;
    for (int i = 0; i < n; i++) {
        vector<int> t;
        int u;
        cin >> u;
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            t.push_back(v - 1);
        }
        graph.push_back(t);
    }

    vector<bool> marked(n);
    vector<int> d(n);
    vector<int> f(n);
    int time = 0;

    for (int i = 0; i < n; i++)
        dfs(graph, i, marked, d, f, time);
    for (int i = 0; i < n; i++)
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;

    return 0;
}