Go: package main

/*
深さ優先探索
*/

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n+1)
	for i := 1; i < n+1; i++ {
		ints := eGetInts(scanner)
		num, vcount := ints[0], ints[1]
		g[i] = make([]int, vcount)
		for j := 0; j < vcount; j++ {
			g[num][j] = ints[j+2]
		}
	}
	hist := make([]struct{ d, f int }, n+1)
	t := 0
	var visit func(int)
	visit = func(num int) {
		if hist[num].d == 0 {
			stack := []int{}
			t++
			hist[num].d = t
			stack = append(stack, num)
			for len(stack) > 0 {
				// トップを訪問する
				top := stack[len(stack)-1]
				for i := 0; i < len(g[top]); i++ {
					if hist[g[top][i]].d == 0 {
						t++
						hist[g[top][i]].d = t
						stack = append(stack, g[top][i])
						goto endloop
					}
				}
				// 訪問場所がなくなったら
				// pop
				stack = stack[0 : len(stack)-1]
				t++
				hist[top].f = t
			endloop:
			}
		}
	}
	for i := 1; i < n+1; i++ {
		visit(i)
	}
	for i := 1; i < n+1; i++ {
		fmt.Println(i, hist[i].d, hist[i].f)
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

C++: #include<iostream>
#include<cstdio>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define N 100
using namespace std;
int M[N][N],n;
int color[N],d[N],f[N],tt;
void dfs_visit(int u)
{
  int v;
  color [u] = GRAY ;
  for(v = 0;v<n;v++)
    {
      if(M[u][v] == 0)
        continue;
      if(color [v] == WHITE )
        {
          dfs_visit(v);
        }
    }
  color[u] = BLACK;
  f[u] = ++tt;
}
void dfs()
{
  int u ;
  for(u = 0;u<n;u++)
    color [u] = WHITE ;
  tt = 0;
  for(u = 0;u<n;u++)
  {
    if(color [u] == WHITE )
      dfs_visit(u);
  }
  for(u = 0;u<n;u++)
    {
      printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}
int main ()
{
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i = 0;i<n;i++)
   {
     for(j = 0;j<n;j++)
      M[i][j] = 0;
   }
  for(i = 0;i<n;i++)
  {
    scanf("%d %d",&u,&k);
    u--;
    for(i = 0;j<k;j++)
      {
        scanf("%d",&v);
        v--;
        M[u][v] =1;
      }
  }
  dfs();
  return  0 ;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int dfs(const int cur, const int par, int time, const vector<vi> &g, vi &d, vi &f) {
  if (d[cur] != 0)
    return time;
  d[cur] = time;
  time++;
  for (const auto u : g[cur]) {
    if (u == par)
      continue;
    time = dfs(u, cur, time, g, d, f);
  }
  f[cur] = time;
  time++;
  return time;
}

int main() {
  int n;
  cin >> n;
  vector<vi> g(n);
  REP(i, n) {
    int id, k;
    cin >> id >> k;
    id--;
    REP(j, k) {
      int u;
      cin >> u;
      u--;
      g[id].push_back(u);
    }
  }

  vi d(n, 0), f(n, 0);
  int time = 1;
  REP(i, n) { time = dfs(i, -1, time, g, d, f); }
  REP(i, n) { cout << i + 1 << " " << d[i] << " " << f[i] << endl; }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll C=0;
ll T[107],T1[107],T2[107];
vector<vector<ll>> V(107);

void dfs(int X){
    T[X]=1;
    C++;
    T1[X]=C;
    rep(i,V[X].size()){
        if(T[V[X][i]]==0){
            dfs(V[X][i]);
        }
    }
    C++;
    T2[X]=C;
}
 
int main(){
    ll N,A,B,C;
    cin >> N;
    rep(i,N){
        cin >> A >> B;
        rep(j,B){
            cin >> C;
            V[A].push_back(C);
        }
    }
    rep(i,N){
        if(T[i+1]==0){
            dfs(i+1);
        }
    }
    rep(i,N){
        cout << i+1 <<" "<< T1[i+1] << " " << T2[i+1] << endl;
    }
}