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;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
//Graph I - Depth First Search - stack version
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B

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

//WHITE -> ????¨?????????????
//GRAY  -> ?¨????????????????(?¨?????????????????¨???????????????????????????????????????§???????????????)
//BLACK -> ?¨??????????????????????(????¨???????????????????????????????????????????)

int n, M[N][N];
int color[N];//?????????????¨??????¶???
int d[N];//????????????
int f[N];//????????????
int tt;//time stamp
int nt[N];

//u?????£??\??????v?????????????????????
int next( int u )
{
	for( int v = nt[u]; v < n; v++ ){
		nt[u] = v + 1;
		if( M[u][v] ) return v;
	}
	return -1;
}
//stack?????¨????????±???????????¢?´¢
void dfs_visit( int r )
{
	for( int i = 0; i < n; i++ ) nt[i] = 0;

	stack<int> S;
	S.push( r );
	color[r] = GRAY;
	d[r] = ++tt;

	while( !S.empty() )
	{
		int u = S.top();
		int v = next(u);
		if( v != -1 )
		{
			if( color[v] == WHITE ){
				color[v] = GRAY;
				d[v] = ++tt;
				S.push(v);
			}
		}else{
			S.pop();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}
void dfs(){
	//?????????
	for( int i = 0; i < n; i++ ){
		color[i] = WHITE;
		nt[i] = 0;
	}
	tt = 0;
	//????¨??????? u ???????§?????????¨????????±???????????¢?´¢
	for( int u = 0; u < n; u++ ){
		if( color[u] == WHITE ) dfs_visit( u );
	}
	for( int i = 0; i < n; i++ ){
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}
int main()
{
	int u;//???????????????
	int k;//??????u?????£??\?????????????????????
	int v;//??????u????¬???°

	cin >> n;

	for( int i = 0; i < n; i++ ){
		for( int j = 0; j < n; j++ ){
			M[i][j] = 0;
		}
	}
	for( int i = 0; i < n; i++ ){
		cin >> u >> k;
		u--;
		for( int j = 0; j < k; j++ ){
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	dfs();
	return 0;
}

C++: #include <iostream>

constexpr int MAXN = 100;
int V[MAXN][MAXN];
int D[MAXN];
int F[MAXN];

template<int STACK_SIZE, typename T = int>
class Stack {

public:
    Stack() {};

    void Push(T val) {
        if (top_ < STACK_SIZE) {
            stack_[top_++] = val;
        }else{
            std::cerr << "Stack over flow..." << std::endl;
            exit(-11);
        }
    };
    bool Pop() {
        if (top_ > 0) {
            stack_[--top_];
            return true;
        }
        return false;
    };

    T Top() {
        return stack_[top_ - 1];
    }

    int Size() {return top_;}


private:
    int max_size_ = STACK_SIZE;
    int top_ = 0;
    T stack_[STACK_SIZE];
};

Stack<MAXN, int> S;

int main() {

    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        int id, e_num;
        std::cin >> id >> e_num;
        for (int j = 0; j < e_num; j++) {
            int t;
            std::cin >> t;
            V[id - 1][t - 1] = 1;
        }
    }
    S.Push(0);

    int cnt = 1;
    D[0] = cnt;
    while (S.Size()) {
        for (int i = 0; i < n; i++) {
            if ((V[S.Top()][i] == 1) && (D[i] == 0)) {
                S.Push(i);
                D[i] = ++cnt;
                break;
            }
            if (i == n - 1) {
                F[S.Top()] = ++cnt;
                S.Pop();
            }
        }
    }

    for (int i = 0; i < n; i++) {
        std::cout << i + 1 << " " << D[i] << " " << F[i] << std::endl;
    }

}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

int ad_num[110];
vector<int> ad[110];
int t=0;
int d[110];
int f[110];

void dfs(int v){
    t++;
    if(d[v]==-1) d[v]=t;
    //if(ad_num[v]==0) return;
    for(auto e: ad[v]){
        //t++;
        if(d[e]==-1) dfs(e);
    }
    t++;
    if(f[v]==-1) f[v]=t;
}

void solve(){

    int n;
    cin >> n;
    rep(i,n){
        int trash;
        cin >> trash;
        cin >> ad_num[i];
        rep(j,ad_num[i]){
            int tmp;
            cin >> tmp;
            tmp--;
            ad[i].emplace_back(tmp);
        }
    }
    rep(i,n){
        d[i]=-1;
        f[i]=-1;
    }
    dfs(0);
    rep(i,n){
        if(d[i]==-1) dfs(i);
    }

    rep(i,n){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }

}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}