Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: //#include <bits/stdc++.h>
#include<iostream>
#include<stack>
#define MAX 100
#define BLACK 2
#define WHITE 0
#define GRAY 1
using namespace std;

void dfsInit();
void dfs(int);
int next(int);

int n,A[MAX][MAX];
int color[MAX],d[MAX],f[MAX],nt[MAX];
int time1;
int main(){
  int i,j,u,v,k;
  cin >> n;
  for(i = 0; i < n; i++){
    for(j = 0; j< n; j++){
      A[i][j] = 0;
    }
  }
  for(i = 0; i < n; i++){
    cin >> u;
    cin >> k;
    u = u-1;
    for(j = 0; j < n; j++){
      cin >> v;
      v = v-1;
      A[u][v] = 1;
    }
  }
  dfsInit();
  return 0;
}

void dfsInit(){
  for(int i = 0; i < n; i++){
    color[i] = WHITE;
    nt[i] = 0;
  }
  time1 = 0;
  for(int u = 0; u < n; u++){
    if(color[u] == WHITE){
      dfs(u);
    }
  }
  for(int i = 0; i < n; i++){
    //printf("%d %d %d\n",i+1,d[i],f[i]);
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
}

int next(int u){
  int v;
  for(v = nt[u]; v < n; v++){
    nt[u] = v+1;
    if(0 < A[u][v]){
      return v;
    }
  }
  return -1;
}
void dfs(int u){
  for(int i = 0; i < n; i++){
    nt[i] = 0;
  }
  stack<int> S;
  S.push(u);
  color[u] = GRAY;
  d[u] = ++time1;
  while(!S.empty()){
    int r = S.top();
    int v = next(u);
    if(v != -1){
      if(color[v] == WHITE){
        color[v] = GRAY;
        d[v] = ++time1;
        S.push(v);
      }
    }
    else{
      S.top();
      color[r] = BLACK;
      f[r] = ++time1;
    }
  }
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }

template<class T>
class DirectedGraph {
public:
	class Edge {
	public:
		int to;
		T cost;

		Edge(int t, T c) : to(t), cost(c) {}
	};

	vector<vector<Edge>> G;
	vector<int> visit;
	vector<pii> stamp{ 0 };
	int V;

	DirectedGraph(int n = 0) {
		resize(n);
	}

	void resize(int n) {
		V = n;
		G.resize(n);
		visit.resize(n);
		stamp.resize(n);
	}

	void addEdge(int from, int to, T cost = 0) {
		int v = max(from, to);
		if (v >= V)
			resize(v + 1);
		G[from].push_back(Edge(to, cost));
	}

	int t = 1;
	void dfs(int s) {
		if (stamp[s].first == 0)
			stamp[s].first = t++;
		else
			return;

		for (int i = 0; i < G[s].size(); ++i) {
			dfs(G[s][i].to);
		}
		stamp[s].second = t++;
	}

	int bfs() {

	}
};

int main() {
	DirectedGraph<int> g;
	int n, id, k, to;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> id >> k;
		while (k--) {
			cin >> to;
			g.addEdge(id, to);
		}
	}

	for (int i = 1; i <= n; ++i) {
		g.dfs(i);
	}
	for (int i = 1; i <= n; ++i) {
		cout << i << " " << g.stamp[i].first << " " << g.stamp[i].second << endl;
	}

	return 0;
}