Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

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;
}