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 <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define N 100

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int M[N][N];
int n, tt, d[N], f[N];
int color[N]; //-1:unvisited, 0:visited, 1:finished
int nt[N];

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


int next(int u){
  FOR(v, nt[u], n){
    nt[u]=v+1;
    if (M[u][v]) return v; // where v is first next_to_u
  }
  return -1;
}


void dfs_visit(int r){
  REP0(i,n) 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);  //次のループで取り出されるu
      }
    }else{ //隣接未探索なし
      S.pop();
      color[u]=BLACK;
      f[u]=++tt;
    }
  }

}


void dfs(){
  REP0(i,n){
    color[i]=WHITE;
    nt[i]=0;
  }
  tt=0;
  REP0(i,n) if (color[i]==WHITE) dfs_visit(i);
  REP0(i,n) std::cout << i+1 << " " << d[i] << " " << f[i] << '\n';
}


void input(int n){
  int v1, v2, d;
  REP0(i,n) { REP0(j,n) M[i][j]=0; }
  REP0(i,n){
    std::cin >> v1 >> d;
    color[v1-1]=-1;
    REP0(j,d){
      std::cin >> v2; M[v1-1][v2-1]=1;
    }
  }
}


int main(int argc, char const *argv[]) {
  cin.tie(0); ios::sync_with_stdio(false);
  std::cin >> n;
  input(n);
  dfs();
  return 0;
}

C++: #include <cstdio>
int dt[101][101];
int d[101], f[101];

int n;
int t=2;
void dfs(int s){
	for(int i=1;i<=n;i++){
		if(dt[s][i]&&d[i]==0){
			d[i]=t;
			t++;
			dfs(i);
		}
	}
	f[s]=t++;
}
int main(){
	int fi, v, g;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d",&fi,&v);
		for(int j=1;j<=v;j++){
			scanf("%d",&g);
			dt[fi][g]=1;
		}
	}
	d[1]=1;
	dfs(1);
	for(int i=1;i<=n;i++){
		printf("%d %d %d\n",i,d[i],f[i]);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#include <cmath>

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef pair<double, double> P;

void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int dfs(int from, int turn, vector<vector<int>> &tos, set<int> &used, vector<vector<int>> &ans) {
    used.erase(from);
    ans[from][1] = turn;
    for (int to : tos[from]) {
        if (contain(used, to)) {
            turn = dfs(to, turn + 1, tos, used, ans);
        }
    }
    turn++;
    ans[from][2] = turn;
    return turn;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> tos(n);
    rep(i, n) {
        int j, k;
        cin >> j >> k;
        j--;
        rep(l, k) {
            int m;
            cin >> m;
            m--;
            tos[j].push_back(m);
        }
    }

    vector<vector<int>> ans(n, vector<int>(3, 0));

    rep(i, n) sort(tos[i].begin(), tos[i].end());
    set<int> used;
    rep(i, n) used.insert(i);
    int turn = 0;
    while (!used.empty()) turn = dfs(*used.begin(), turn + 1, tos, used, ans);

    rep(i, n) ans[i][0] = i + 1;
    rep(i, n) print_line(ans[i]);
}