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 FOR(i,a,b) for(int i= (a); i<(b); i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
using namespace std;

const long long INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
typedef long long ll;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<bool> seen;
vector<int> start_time;vector<int> finish_time;
vector<vector<int> > g;
void dfs(int ind,int& cnt){
    start_time[ind]=++cnt;
    seen[ind]=true;
    for(int nextind : g[ind]){
        if(seen[nextind])continue;
        dfs(nextind,cnt);
    }
    finish_time[ind]=++cnt;
}
signed main () {
    int n;scanf("%d",&n);
    g.resize(n);
    REP(i,n){
        int ind,tmp;scanf("%d %d",&ind,&tmp);
        REP(j,tmp){
            int a;scanf("%d",&a);
            g[i].push_back(a-1);
        }
    }
    seen.assign(n,false);start_time.resize(n);finish_time.resize(n);
    int cnt =0;
    REP(i,n){
        if(seen[i])continue;
        dfs(i,cnt);
    }
    REP(i,n){
        printf("%d %d %d\n",i+1,start_time[i],finish_time[i]);
    }
    return 0;
}

C++: #include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

int g[101][101],n,d[101],f[101];

int main() {
    cin >> n;
    for(int i = 0;i < n;i++) {
        int u,k,v;
        cin >> u >> k;
        for(int j = 0;j < k;j++) {
            cin >> v;
            g[u][v]++;
        }
    }
    stack<int> dfs;
    int time = 2;
    dfs.push(1);
    d[1] = 1;
    while(!dfs.empty()){
        int u = dfs.top();
        bool fl = false;
        for(int i = 1;i <= n;i++){
            if(g[u][i] && d[i] == 0 && u != i) {
                dfs.push(i);
                cout << "push" << i  << "u:" << u<< endl;
                d[i] = time++;
                fl = true;
                break;
            }
        }
        if(!fl) {
            dfs.pop();
            f[u] = time++;
        }
    }
    for(int i = 1;i <=n;i++) {
        cout << i << " " << d[i] << " " << f[i] <<endl;
    }
}

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

typedef long long ll;
#define inf 1e9+7

int f[200],d[200];
bool table[200][200];
int cou;

void init(){
    for(int i=0;i<200;i++){
        f[i]=d[i]=-1;
    }
}

void dfs(int n,int itr){
    cou++;
    if(d[itr]<0)d[itr]=cou;
    for(int i=0;i<n;i++){
        if(d[i]<0&&table[itr][i]) dfs(n,i);
    }
    cou++;
    f[itr] = cou;
}

void solve(int n){
    for(int i=0;i<n;i++){
        if(d[i]<0)dfs(n,i);
    }
}

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


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

    solve(n);

    for(int i=0;i<n;i++){
        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){
  fincou++;
  Fcounter++;

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

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

      }
    }
  }
    FinIt[where] = fincou;
     
}
 
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 = 1;
  int Index=0;
  bool fin = true;
  
    for(int i=0;i<n;i++){
      if(!used[u[i]]){//cout << "not used" << u[i] << endl;
	//used[u[i]]=true;
      dfs(u[i]);
      Find = fincou+1;
      fincou++;      
    
      }
    }
  
  //dfs(u[0]);   

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