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++: #include <iostream>
#include <cstdio>
#include <stack>
#include <vector>

static const int N = 101;

using namespace std;

vector<vector<int> > V;
int d[N], f[N];
int step = 1;

void dfs (int v) {
  if (d[v])
    return;

  d[v] = step++;

  for (vector<int>::iterator it = V[v].begin(); it != V[v].end(); it++) {
    if (!d[*it]) {
      dfs(*it);
    }
  }

  f[v] = step++;
}

void dfs_init (int n) {
  for (int i = 1; i <= n; i++)
    dfs(i);
}

int main () {
  int n, v, v2, k;
  // stack<int> S;
  // vector<vector<int> > V;

  for (int i = 0; i <= N; i++) {
    vector<int> A;
    V.push_back(A);
  }
  for (int i = 0; i <= N; i++)
    d[i] = f[i] = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> v >> k;

    for (int j = 0; j < k; j++) {
      cin >> v2;
      V[v].push_back(v2);
    }
  }

  // for (int i = 1; i <= n; i++) {
  //   for (int j = 1; j <= n; j++)
  //     cout << V[i][j] << (j == n ? "" : " ");
  //   cout << endl;
  // }

  // int step = 1;
  // bool breaked = false;

  // S.push(1);
  // d[S.top()] = step++;

  // while (S.size()) {
  //   // cout << "S.top = " << S.top() << endl;
  //   breaked = false;

  //   for (vector<int>::iterator it = V[S.top()].begin(); it != V[S.top()].end(); it++) {
  //     if (!d[*it]) {
  //       d[*it] = step++;
  //       S.push(*it);
  //       breaked = true;
  //       break;
  //     }
  //   }

  //   if (!breaked) {
  //     f[S.top()] = step++;
  //     S.pop();

  //     if (S.empty()) {
  //       for (int i = 1; i <= n; i++) {
  //         if (!d[i]) {
  //           S.push(i);
  //           d[i] = step++;
  //           break;
  //         }
  //       }
  //     }
  //   }
  // }

  dfs_init(n);

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

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
using namespace std;

void dfs(vector<int> &discover, vector<int> &finished, vector<vector<bool>> &g, int n, vector<int> &color, int &time, int u){
    color[u]++;
    discover[u] = ++time;
    for (int i = 0; i < n; i++){
        if (g[u][i]){
            if (color[i] == 0){
                dfs(discover, finished, g, n, color, time, i);
            }
        }
    }
    color[u]++;
    finished[u] = ++time;
}

int main(){
    int n, u, k;
    int time = 0;
    cin >> n;
    vector<int> discover(n);
    vector<int> finished(n);
    vector<int> color(n, 0);
    vector<vector<bool>> g(n, vector<bool>(n, false));
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        u--;
        int v;
        for (int j = 0; j < k; j++){
            cin >> v;
            v--;
            g[u][v] = true;
        }
    }

    for (int j = 0; j < n; j++){
        if (!color[j]){
            dfs(discover, finished, g, n, color, time, j);
        }
    }

    for (int i = 0; i < n; i++)
        cout << i + 1 << ' ' << discover[i] << ' ' << finished[i] << endl;
    return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GREY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];


int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (M[u][v]) return v;
	}
	return -1;
}


void dfs_visit(int r) {
	for (int i = 0; i < n; i++) nt[i] = 0;

	stack<int> S;
	S.push(r);
	color[r] = GREY;
	d[r] = ++tt;

	while (!S.empty()) {
		int u = S.top();
		int v = next(u);
		if (v != -1) {
			if (color[v] == WHITE) {
				color[v] = GREY;
				d[v] = ++tt;
				S.push(v);
			}
		}
		else {
			S.pop();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}


void dfs() {
	for (int i = 0; i < n; i++) {
		color[i] = WHITE;
		nt[i] = 0;
	}
	tt = 0;

	for (int u = 0; u < n; u++) {
		if (color[u] == WHITE) dfs_visit(u);
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}


int main() {
	int u, k, v;

	cin >> n;
	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++: /*
 * ALDS1_11_B.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<iostream>
#include<vector>

using namespace std;

int d[101];
int f[101];
int nowTime;

void dfsRec(vector<int>* a, int n, int v) {
	if(d[v] > 0) return;
	nowTime++;
	d[v] = nowTime;
	for(int &x:a[v]) {
		dfsRec(a, n, x);
	}
	nowTime++;
	f[v] = nowTime;
}

int main() {
	int n;
	vector<int> adj[101];

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

	dfsRec(adj, n, 1);

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

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int M[200][200];
string color[200];
int d[200];
int f[200];
int t = 0;
int n;

void dfs(int u){
    color[u] = "GRAY";
    d[u] = ++t;
    for (int i = 0; i < n; i++){
        if(M[u][i] && color[i] == "WHITE"){
            dfs(i);
        }
    }
    color[u] = "BLACK";
    f[u] = ++t;
}

void dfs_init(){
    rep(i, n){
        color[i] = "WHITE";
    }
    rep(i, n){
        if(color[i] == "WHITE"){
            dfs(i);
        }
    }
}

int main() {
    cin >> n;
    rep(i, n){
        int a, b; cin >> a >> b;
        rep(j, b){
            int x; cin >> x;
            x--;
            M[i][x] = 1;
        }
    }
    dfs_init();
    rep(i, n){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int visit[101],d[101],f[101],t;
//   訪問状態     発見    完了
int n,M[101][101];
const int WHITE=0; //未訪問
const int GRAY=1;  //訪問はした
void dfs(int u){
  visit[u]=GRAY; //訪問はした
  d[u]=++t; //発見した時刻
  for(int v=0;v<n;v++){
    if(M[u][v]==0) continue; //辺がない
    if(visit[v]==WHITE) dfs(v);
  }
  f[u]=++t; //訪問完了時刻
}
int main(){
  int u,v,k;
  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--;
      M[u][v]=1;
    }
  }
  for(int i=0;i<n;i++){
    if(visit[i]==WHITE) //訪問していないか
      dfs(i); //iを始点に
  }
  for(int i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}