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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------
int N, turn;
int d[111], f[111];
vector<vector<int>> G;

void dfs(int from) {
   d[from] = ++turn;
   for (int to : G[from]) {
      if (!d[to]) dfs(to);
   }
   f[from] = ++turn;
}

int main() {
   // 入力
   cin >> N;
   G = vector<vector<int>>(N);
   rep (i, N) {
      int u, k;
      cin >> u >> k;
      u--;
      rep (j, k) {
         int a;
         cin >> a;
         a--;
         G[u].push_back(a);
      }
   }

   rep (i, N) {
      if (!d[i]) dfs(i);
   }

   rep (i, N) {
      printf("%d %d %d\n", i+1, d[i], f[i]);
   }

   return 0;
}

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

int num = 1;
bool visited[1000];
vector<int> v[1000], seq[1000];
void dfs(int k){
    seq[k].pb(num++);
    if(visited[k]) return;
    visited[k] = 1;
    for (auto t : v[k]){
        if(visited[t]) continue;
        dfs(t);
    }
    seq[k].pb(num++); return;

}
int main(){
    int n; cin >> n;
    memset(visited, 0, sizeof(visited));
    for (int i = 0; i < n; i++){
        int x, y, z; cin >> x >> y;
        for (int j = 0; j < y; j++){
            cin >> z; v[x].pb(z);
        }
    }
    for(int i = 1; i <= n; i++)
        sort(v[i].begin(), v[i].end());
    dfs(1);
    for (int i = 1; i <= n; i++){
        cout << i << ' ';
        for (auto k : seq[i])
        cout << k << ' ';
        cout << '\n';
    }
}

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

using namespace std;

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

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);
        }
    }

    while (1) {
        int s = -1;
        for (int i = 1; i <= n; i++) {
            if (node[i].start == 0) {
                s = i;
                break;
            }
        }
        if (s == -1) {
            break;
        }
        
        node[s].start = time++;
        st.push(s);
        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 <iostream>
#include <stdio.h>
#include <string>
using namespace std;

#define N 105

struct Node{
    string color;
    int d;
    int f;
};

struct Node node[N];
int tt;
int AdjMat[N][N];

void DFS(int u, int n){
    node[u].color = "gray";
    node[u].d = ++tt ;
    for (int v = 1; v <= n; v++){
        if ( AdjMat[u][v] == 0 ) continue;
        if ( node[v].color == "white") DFS(v, n);
    }
    node[u].color = "black";
    node[u].f = ++tt;
}

void DFS_init(int n){
    for (int i = 1; i <= n; i++){
        node[i].color = "white";
    }
    tt = 0;
    
    for (int i = 1; i <= n; i++){
        if (node[i].color == "white") DFS(i, n);
    }
    for (int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, node[i].d, node[i].f);
    }
}

int main(){
    
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; i++ ){
        for (int j = 1; j <= n; j++){
            AdjMat[i][j] = 0;
        }
    }
    
    for (int i = 1; i <= n; i++){
        int u, k, v;
        cin >> u >> k;
        if ( k == 0 ) continue;
        for (int j = 1; j <= k; j++){
            cin >> v;
            AdjMat[u][v] = 1;
        }
        
    }
    DFS_init(n);
    
    return 0;
}