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++: #define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string.h>
#include <string>
#include <vector>
#include <stack>

using namespace std;

#define INF 2e9 + 9
#define ALL(v) v.begin(), v.end()
#define Int int64_t
#define pll pair<Int, Int>
template <class T>
using pql = priority_queue<T, vector<T>>;
template <class T>
using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) \
    Int n;    \
    cin >> n;
#define LL(...)       \
    Int __VA_ARGS___; \
    cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for (Int i = s; i < n; i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) \
    if (maxer < updater)        \
        maxer = updater;

vector<vector<Int>> to;
vector<Int> d;
vector<Int> f;
/*
Int dfs(Int from, Int time){
    if (d[from] != 0) return 0;
    Int maxer = time;
    d[from] = time;
    Int cnt = 0;
    for (auto next : to.at(from)){
        maxer= max(dfs(next,maxer+1),maxer);
    }
    if (maxer == 0) return f[from] = d[from];
    return f[from] = maxer+1;
}*/


/*
    stackの挿入ルール
    未探索だと思って追加する時はpairの2つめの値を0とする
    既探索だけど、完了時刻を確認するためにstackに追加する時は-1とする
    -1ならnowtimeを追加、nowtime++して次へ飛ばす
    違ったら、自分が本当に未探索かどうかを判断した上で、未探索であれば
    自分の発見時刻をメモ、次に探索する所を追加して、ターン終了
*/
Int dfs(Int x, Int t){
    Int nowtime = t;
    stack<pll> st;
    st.push({x,0});
    while(!st.empty()){
        //stackから取り出してきて
        auto z = st.top();
        Int from = z.first;
        Int op = z.second;
        st.pop();

        if (op == -1) { // 完了時刻の記入
            f[from] = nowtime;
            nowtime++;
        }

        if (d[from] != 0) continue;

        //ここから未探索確定
        st.push({from,-1});
        d[from] = nowtime;
        nowtime++;
        for (int i = to[from].size() - 1; i >= 0; i--){//次探索する箇所は、未探索だと思って挿入
            st.push({to[from][i],0});
        }
    }
    return nowtime;
}



int main() {
    Int n;
    cin >> n;
    to.resize(n);
    d.resize(n);
    f.resize(n);

    REP(n,i){
        Int u, k;
        cin >> u >> k;
        REP(k,kk) {
            Int x;
            cin >> x;
            x--;
            to.at(i).push_back(x);
        }
    }
    
    Int time = 1;
    
    REP(n,i){
        if (d[i] == 0){
            //time = dfs(i,time) + 1;
            time = dfs(i,time);
        }
    }  

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

}

C++: //
// Created by tattsun on 2017/02/13.
//

#include <iostream>
#include <vector>

using namespace std;

#define VERTEX_MAX_NUM 101
#define NIL -1

int now = 0;
int n;
int start[VERTEX_MAX_NUM];
int finish[VERTEX_MAX_NUM];
bool visited[VERTEX_MAX_NUM];
vector<int> vertexes[VERTEX_MAX_NUM];

void _dfs(int node) {
    cout << node << endl;
    start[node] = ++now;
    visited[node] = true;

    auto& v = vertexes[node];

    for(auto it = v.begin(); it != v.end(); it++) {
        if(visited[*it])
            continue;
        _dfs(*it);
    }

    finish[node] = ++now;
}

void dfs() {
    for(int i=1; i<=n; i++) {
        if(visited[i]) continue;
        _dfs(i);
    }
}

int main() {
    for(int i=0; i<VERTEX_MAX_NUM; i++) {
        start[i] = NIL;
        finish[i] = NIL;
        visited[i] = false;
    }

    cin >> n;

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

    dfs();

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

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

vector<vector<int>> G;
vector<bool> seen;
vector<pair<int,int>> ts;
int cnt=1;

void dfs(int v){
    seen[v]=true;
    ts[v].first = cnt;
    cnt++;

    for(auto next_v : G[v]){
        if(seen[next_v])continue;
        dfs(next_v);
    }
    ts[v].second = cnt;
    cnt++;
}

int main(){
    int N; 
    cin>>N;
    G.resize(N);
    ts.resize(N);
    rep(i,N){
        int u,k; 
        cin>>u>>k;
        rep(j,k){
            int vz; 
            cin>>vz;
            G[u-1].push_back(vz-1);
        }
    }
    seen.assign(N, false);
    for(int i=0; i<N; i++){
        if(!seen[i])dfs(i);
    }
    rep(i,N){
        cout<<i+1<<" "<<ts[i].first<<" "<<ts[i].second<<endl;
    }
    return 0;
}