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

	timer := 1
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	return x
}

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++: /*
 * 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 time;

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

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<iostream>
#include<string>
using namespace std;

void dfs_init();
void dfs(int u);

int n,**List,*deg,*d,*f;
bool **M;
string *color;
int vertex;
int tm;

int main(){
	cin>>n;
	List = new int*[n]; M = new bool*[n]; deg = new int[n]; color = new string[n]; d = new int[n]; f = new int[n];
	for(int i=0;i<n;i++) List[i] = new int[n]; for(int i=0;i<n;i++) M[i] = new bool[n];
	for(int i=0;i<n;i++){
		List[i] = List[i]-1;
		M[i] = M[i]-1;
	}
	List = List-1; M = M-1; deg = deg-1; color = color-1; d = d-1; f = f-1;

	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			M[i][j] = false;
		deg[i] = 0; d[i] = 0; f[i] = 0;
	}
	
	int k;
	for(int i=1;i<=n;i++){
		cin>>vertex>>k;
		for(int j=1;j<=k;j++){
			cin>>List[vertex][j];
			M[vertex][List[vertex][j]] = true;
		}
	}

	dfs_init();

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

	for(int i=1;i<=n;i++){
		delete [] (List[i]+1); delete [] (M[i]+1);
	}
	delete [] (List+1); delete [] (M+1);
	delete [] (deg+1); delete [] (color+1); delete [] (d+1); delete [] (f+1);
	cin.get(); cin.get();
}

void dfs_init(){
	for(int i=1;i<=n;i++) color[i] = "WHITE";
	tm = 0;
	for(int i=1;i<=n;i++){
		if(color[i]=="WHITE"){
			dfs(i);
		}
	}
}

void dfs(int u){
	color[u] = "GRAY";
	d[u] = ++tm;
	for(int v=1;v<=n;v++){
		if(M[u][v]==false) continue;
		if(color[v]=="WHITE"){
			dfs(v);
		}
	}
	color[u] = "BLACK";
	f[u] = ++tm;
}

C++: //aizu
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
using namespace std;

vector <int> v[101];

pair <int, int> af[101];

bitset <101> viz;

int cnt;

void DFS(int nod)
{
    cnt++;
    af[nod].first = cnt;
    viz[nod] = 1;

    for (size_t i = 0; i < v[nod].size(); ++i)
    {
        if (viz[v[nod][i]] == 0)
            DFS(v[nod][i]);
    }
    cnt++;
    af[nod].second = cnt;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n, u, k, ind;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> u >> k;
        for (int j = 1; j <= k; ++j)
        {
            cin >> ind;
            v[u].push_back(ind);
        }
        sort(v[u].begin(), v[u].end());
    }

    for (int i = 1; i <= n; ++i)
        if (viz[i] == 0)
            DFS(i);

    for (int i = 1; i <= n; ++i)
        cout << i << " " << af[i].first << " " << af[i].second << "\n";
    return 0;
}

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

int N;
int a[110][110]={{0}};
int d[110][5]={{0}};
int T=1;

void dfs(int cur);

int main(){
        cin >> N;
        for(int i=0; i<N; i++){
                int v,n;
                cin >> v;
                cin >> n;
                for(int j=0; j<n; j++){
                        int V;
                        cin >> V;
                        a[v-1][V-1]=1;
                }
        }
        for(int i=0; i<N; i++){
                if(!d[i][0])dfs(i+1);
        }
        for(int i=0; i<N; i++){
                cout << i+1 << " ";
                for(int j=0; j<2; j++){
                        cout << d[i][j];
                        if(!j)cout << " ";
                }
        cout << endl;
        }
}


void dfs(int cur){
        d[cur-1][0]=T;
        T++;
        //cerr << "visiting_" << cur << " " << T << endl;
        for(int i=0; i<N; i++){
                if(a[cur-1][i] && !d[i][0])dfs(i+1);
        }
        d[cur-1][1]=T;
        T++;
        if(cur>1)cur--;
}

C++: #include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vvll edge(110, vll(0));
vll d(110, -1), f(110, -1);

void dfs(int n, int &time){
  if(edge.at(n).size() == 0){
    d.at(n) = time;
    time++;
    f.at(n) = time; time++;
    return;
  }
  d.at(n) = time; time++;
  bool flag = true;
  for(int i = 0; i < edge.at(n).size(); i++){
    if(d.at(edge.at(n).at(i)) == -1){
      dfs(edge.at(n).at(i), time);
    }
  }
  f.at(n) = time; time++;
}

int main(){
  int n;
  cin >> n;
  
  for(int i = 0; i < n; i++){
    int u, k;
    cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      ll v;
      cin >> v;
      v--;
      edge.at(u).push_back(v);
    }
  }
  int time = 1;
  for(int i = 0; i < n; i++){
    if(d.at(i) == -1) dfs(i, time);
  }
  
  for(int i = 0; i < n; i++){
    cout << i+1 << ' ' << d.at(i) << ' ' << f.at(i) << endl;
  }

}