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 <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

const int MAX = 110;
vector<int> G[MAX];
int dtime[MAX];
int ftime[MAX];
int n;
int tim;

void dfs(int p) {
    if (ftime[p] == -1) dtime[p] = ++tim;
    else return;
    for (int i = 0; i < G[p].size(); i++) {
        dfs(G[p][i]);
    }
    if (ftime[p] == -1) ftime[p] = ++tim;
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {G[i].clear(); dtime[i]=-1; ftime[i]=-1;}
    tim = 0;
    for (int i = 1; i <= n; i++) {
        int p, k;
        scanf("%d %d", &p, &k);
        while (k--) {
            int ne = 0;
            scanf("%d", &ne);
            G[p].push_back(ne);
        }
        sort(G[p].begin(), G[p].end());
    }
    for (int i = 1; i <= n; i++) {
        dfs(i);
    }
    for (int i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, dtime[i], ftime[i]);
    }
    return 0;
}

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

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int mat[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]+=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(mat[dst][cur]==1&&c[dst]==0){
			dfs(dst);
		}
	}
	t += 1; 
	mytime2[cur]=t;
}


int main()
{
	vector<int> v[110];
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int tmp;
			cin>>tmp;
			v[u].push_back(tmp);
		}
	}
	for(int i=0;i<100;i++){
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			mat[i][j]=0;
		}
	}
	for(int i=1;i<n+1;i++){
		for(int j=0;j<v[i].size();j++){
			mat[i-1][v[i][j]-1]=1; //
		}
	}
	for(int i=0;i<n;i++){
    if(c[i]!=1){
      dfs(i);
    }
  }
  for(int i=0;i<n;i++)
    {
      cout<<(i+1)<<' '<<mytime1[i]<<' '<<mytime2[i]<<endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 105
#define BLACK 0
#define GRAY 1
#define WHITE 2

int n;
int G[MAX][MAX];
int d[MAX], f[MAX], color[MAX];
int t;

void init();
void dfs();
void dfs_s(int s);

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

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

    dfs();

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

void init(){
    t = 1;
    for(int i = 0; i < n; i++){
        d[i] = f[i] = 0;
        color[i] = WHITE;
        for(int j = 0; j < n; j++){
            G[i][j] = 0;
        }
    }
}

void dfs(){
    for(int i = 0; i < n; i++){
        if(color[i] == WHITE){
            dfs_s(i);
            t++;
        }
    }
}

void dfs_s(int s){
    stack<int> S;
    S.push(s); color[s] = GRAY; d[s] = t;
    int now;

    while(!S.empty()){
        now = S.top();
        t++;
        bool fl = true;

        for(int i = 0; i < n; i++){
            if(G[now][i] == 1 && color[i] == WHITE){
                S.push(i); color[i] = GRAY; d[i] = t;
                now = i; fl = false; break;
            }
        }

        if(fl){
            int top = S.top(); S.pop();
            color[top] = BLACK; f[top] = t;
            now = top;
        }
    }
}