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>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

constexpr int LEN = 105;
bool ga[LEN][LEN];
int d[LEN], f[LEN];

int dfs(int id, int time, const int n){
	int	t = ++time;
	if(d[id] < 0) d[id] = t;
	rep(i, n)
		if(ga[id][i] && (d[i] < 0)) t = dfs(i, t, n);
	if(f[id] < 0) f[id] = ++t;

	return t;
}

int main(){
	memset(d, -1, LEN*sizeof(int));
	memset(f, -1, LEN*sizeof(int));
	memset(ga, 0, LEN*LEN*sizeof(bool));
	int n; cin >> n;
	rep(i, n){
		int u, k; cin >> u >> k;
		rep(j, k){
			int v; cin >> v;
			ga[u-1][v-1] = 1;
		}
	}

	int t = 0;
	rep(id, n) if(d[id] < 0) t = dfs(id, t, n);
	rep(i, n) cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;

	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int arisutoteresu[200][200] = {0};
int imap[200][200] = {0};
int n,u[200],k[200];
int GetIt[200]={0};
int FinIt[200]={0};
bool used[200];
int fincou=1;
int Gcounter;
int Fcounter;
int Find;
void dfs(int where){
  Find++;
  //cout << "where " << where << " " << Find << endl; 
 GetIt[where]=Find;
  //cout << "GetIt[" << where << "] = " << GetIt[where] << endl;

  if(k[where] != 0){ 
    for(int i=0;i<k[where];i++){
      if(!used[imap[where][i]]){
	Gcounter++;

	used[imap[where][i]] = true;
	dfs(imap[where][i]);

      }
    }
  }
  Find++;
    FinIt[where] = Find;
     
}
 
int main(){
  
  int ad;
   
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> u[i];
    cin >> k[u[i]];
    for(int j=0;j<k[u[i]];j++){
      cin >> ad;
      imap[u[i]][j] = ad;
    }
  }
 
 
  for(int j=0;j<200;j++)used[j] = false;
  Gcounter=Fcounter=1;
 
  Find = 0;
  int Index=0;
  bool fin = true;
  fincou = 1;

  
    for(int i=0;i<n;i++){
      if(!used[u[i]]){//cout << "not used" << u[i] << endl;
	used[u[i]]=true;
	dfs(u[i]);

      }
    }
    
    //dfs(u[0]);   

   
  
  //cout << "counter - " << Find << ", F" << fincou << endl;
  for(int i=0;i<n;i++){
    cout << u[i] << " " << GetIt[u[i]]  << " " << FinIt[u[i]];
    cout << endl;
  }
 
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef vector<vector<long long>> Graph;
vector<bool> seen(110, false);
vector<int> first_order(110);
vector<int> last_order(110);
int ptr = 0;
void dfs(Graph& G, int v) {
    ptr++;
    first_order[v] = ptr;
    seen[v] = true;
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue;
        dfs(G, next_v);
    }
    ptr++;
    last_order[v] = ptr;
    return;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    long long N; cin >> N;
    Graph G(N);
    rep(i, N) {
        int u, k; cin >> u >> k;
        rep(j, k) {
            int v; cin >> v;
            G.at(u - 1).push_back(v - 1);
        }
    }
    rep(i, N) {
        if (!seen.at(i)) dfs(G, i);
    }
    rep(i, N) {
        cout << i + 1 << ' ' << first_order.at(i) << ' ' << last_order.at(i) << endl;
    }
}