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++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C
#include <iostream>
#include <cstdio>
#include <queue> // 入れた順番に出していく玉突き構造。
using namespace std;

int G[110][110];
int n;
int u, k, v;

/* void print_matrix(int N) {
  for(int i=0; i<N; i++) {
    for(int j=0; j<N; j++) {
      printf("%d", G[i][j]);
      if (j < N-1) {
	printf(" ");
      }
    }
      printf("\n");
  }
} */

void make_matrix() {
  fill(&G[0][0], &G[0][0]+110*110, 0);
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf("%d%d", &u, &k);
    u--;
    for (int j=0; j<k; j++) {
      scanf("%d", &v);
      v--;
      G[u][v] = 1;
    }
  }
}

int timer = 1; // timeだとエラーが出たので。
int d[110]; // 訪問時刻。ナマの数字を入れる。
int f[110]; // 終了時刻。ナマの数字を入れる。

void init() {
  fill(d, d+110, -1);
  fill(f, f+110, -1);
}

void dfs(int cur) { // curを訪問。
  d[cur] = timer;
  timer++;
  // cerr << "visiting " << cur << " at the time " << timer << endl;
  for (int i=1; i<=n; i++) { // 節点i
    if (G[cur-1][i-1] == 1 && d[i] == -1) {
      dfs(i);
    }
  }
  f[cur] = timer;
  timer++;
}

int main() {
  make_matrix();
  init();
  dfs(1);
  for (int i=1; i<=n; i++) {
    printf("%d %d %d\n", i, d[i], f[i]);
  }
}

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

int	dfs(const Graph &graph,
		vector<int> &d_vec, vector<int> &f_vec, int u, int cur_time)
{
	d_vec.at(u) = ++cur_time;
	for (int v : graph.at(u)) {
		if (d_vec.at(v) != -1)
			continue;
		cur_time = dfs(graph, d_vec, f_vec, v, cur_time);
	}
	f_vec.at(u) = ++cur_time;
	return cur_time;
}	
		
int	main()
{
	int	n;
	cin >> n;
	Graph graph(n);
	vector<int>	d_vec(n, -1);
	vector<int>	f_vec(n, -1);
	int	k;
	int	u, v;
	for (int i = 0; i < n; ++i) {
		cin >> u >> k;
		--u;
		for (int j = 0; j < k; ++j) {
			cin >> v;
			--v;
			graph.at(u).push_back(v);
		}
	}
	int cur_time = 0;
	for (int i = 0; i < n; ++i) {
		if (d_vec.at(i) != -1)
			continue;
		cur_time = dfs(graph, d_vec, f_vec, i, cur_time);
	}
	for (int i = 0; i < n; ++i) {
		cout << i + 1 << " " << d_vec.at(i) << " " << f_vec.at(i) << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
const int MAX=100;
const int WHITE=0;
const int GRAY=1;
const int BLACK=2;
using namespace std;
int M[MAX][MAX],d[MAX],f[MAX],tt,n,color[MAX];

void dfs_visit(int i){
    color[i]=GRAY;
    d[i]=++tt;
    for(int u=0;u<n;u++){
        if( M[i][u]==0)continue;
        dfs_visit(u);
    }
    color[i]=BLACK;
    f[i]=++tt;
}





void dfs(){
    int i;
    for(i=0;i<n;i++){
        color[i]=0;
    }
    tt=0;
    for(i=0;i<n;i++){
        if( color[i]==WHITE)dfs_visit(i);
    }
    for(i=0;i<n;i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}
int main(){
  //  cout<<"A"<<endl;
    cin>>n;
    int u,v,k;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            M[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    dfs();
    return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

const int MAX = 101;

vector<int> G[MAX];
int d[MAX], f[MAX];
int *T;

void dfs(int u) {

    if (!d[u]) d[u] = ++(*T);

    for (int v : G[u]) {
        if (!d[v]) d[v] = ++(*T);
        dfs(v);
    }

    if (!f[u]) f[u] = ++(*T);
}

int main() {

    int n;
    cin >> n;

    int t = 0;
    T = &t;
    fill(d, d + MAX, 0);
    fill(f, f + MAX, 0);

    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            G[u].push_back(v);
        }
    }

    for (int i = 1; i <= n; i++) {
        if (!d[i]) dfs(i);
    }


    for (int i = 1; i <= n; i++) {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
}

C++: #include <iostream>
#include <map>
#include <vector>

using namespace std;
struct node {
    node() {};
    node(int i, int n, int* xs) : id {i}, ns {vector<int>(xs, xs+n)} {
        delete xs;
    };
    int id;
    vector<int> ns;
    int in_time;
    int out_time;
};

int dfs(map<int, node*> graph, int time, int id){
    node* n = graph[id];
    if(n->in_time > 0){
        return time;
    }
    n->in_time = ++time;
    vector<int> ns = n->ns;
    for(auto it = ns.begin(); it != ns.end(); ++it){
        time = dfs(graph, time, *it);
    }
    n->out_time = ++time;
    return time;
}

int main(){
    int n;
    cin >> n;
    map<int, node*> graph {};
    int st = 1000000000;
    for(int i = 0; i < n; ++i){
        int id;
        cin >> id;
        st = min(st, id);
        int k;
        cin >> k;
        int* ns = new int[k];
        for(int j = 0; j < k; ++j){
            cin >> ns[j];
        }
        graph[id] = new node(id, k, ns);
    }
    int time = 0;
    for(auto it = graph.begin(); it != graph.end(); ++it){
        pair<int, node*> p = *it;
        if(p.second->in_time){
            continue;
        }
        time = dfs(graph, time, p.first);
    }
    for(auto it = graph.begin(); it != graph.end(); ++it){
        pair<int, node*> p = *it;
        cout << p.first << ' ' << p.second->in_time << ' ' << p.second->out_time << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define WHITE 0
#define GRAY 1
#define BLACK 2
vector<vector<int>> M(100, vector<int>(100));
vector<int> C(100);
int n, tt;
vector<int> ST(100), PT(100);

int next(int u) {
  rep(i, n) {
    if (M.at(u).at(i) == 1 && C.at(i) == WHITE) {
      return i;
    }
  }
  return -1;
}

void dfs_visit(int u) {
  stack<int> S;
  S.push(u);
  ST.at(u) = ++tt;
  C.at(u) = GRAY;
  while (S.size() > 0) {
    int t = S.top();
    int v = next(t);
    if (v!=-1) {
      if (C.at(v) == WHITE) {
        S.push(v);
        ST.at(v) = ++tt;
        C.at(v) = GRAY;
      }
    } else {
      S.pop();
      PT.at(t) = ++tt;
      C.at(t) = BLACK;
    }
  }
}

void dfs() {
  tt = 0;
  rep(u, n) if (C.at(u) == WHITE) dfs_visit(u);
}

int main() {
  cin >> n;
  rep(i, n) {
    int id, k; cin >> id >> k;
    rep(j, k) {
      int num; cin >> num;
      M.at(id-1).at(num-1) = 1;
    }
  }
  dfs();

  rep(i,n) cout << i+1 << " " << ST.at(i) << " " << PT.at(i) << endl;
  return 0;
}