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 <stack>
using namespace std;

int main(){
	int n;
	cin >> n;

	int G[100][100]={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-1][v-1] = 1;
		}
	}

	int d[100] = {0};
	int f[100] = {0};

	stack<int> S;
	int T=0;

	for(int i=0; i<n; i++){
		if(d[i]!=0)
			continue;
		S.push(i);
		d[i] = ++T;

		while(!S.empty()){
			int u = S.top();
			int v = -1;
			for(int j=0; j<n; j++){
				if(G[u][j]==1 && d[j]==0){
					v = j;
					break;
				}
			}

			if(v!=-1){
				S.push(v);
				d[v] = ++T;
			}else{
				S.pop();
				f[u] = ++T;
			}
		}
	}
	
	for(int i=0; i<n; i++){
		cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#define N 100
#define  GRAY 1
#define BLACK 2
int n,M[N][N];
int color[N],d[N],f[N],tt;
void dfs_visit(int u)
{
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v = 0;v<n;v++)
  {
    if(M[u][v] == 0)
     continue;
  if(color[v] == 0)
    {
      dfs_visit(v);
    }
}
  color[u] = BLACK;
  f[u] == ++tt;
}
void dfs()
{
  int u;
  for(u = 0;u<n;u++)
     color[u] = 0;
  tt = 0;
  for(u = 0;u<n;u++)
  {
    if(color[u] == 0) dfs_visit(u);
  }
  for(u = 0;u<n;u++)
  {
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
int main ()
{
  int u,v,k,i,j;
  scanf("%d",&n);
  for( i = 0;i<n;i++)
  {  for( j = 0;j<n;j++)
        M[i][j] = 0; }
  for( i =0;i<n;i++)
   {
     scanf("%d %d",&u,&k);
     u--;
     for( j = 0;j<k;j++)
       {
         scanf("%d",&v);
         v--;
         M[u][v] = 1;
       }
   }
   dfs();
  return  0 ;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

typedef pair<int,int> P;

vector<int> g[100];
int ans[100][2]; //[i][0] 到着　　[i][1] 終了
bool used[100];

int dfs(int v,int t){
	used[v] = true;
	ans[v][0] = t++;
	for(int i=0;i<g[v].size();i++){
		if(!used[g[v][i]]) t = dfs(g[v][i],t);
	}
	ans[v][1] = t;
	return t + 1;
}

int main(){
	//ios::sync_with_stdio(false);
	//cin.tie(0);

	int n;
	cin >> n;
	
	for(int i=0;i<n;i++){
		int u, nume;
		cin >> u >> nume;

		int v;
		for(int j=0;j<nume;j++){ //jは回数数えるだけ
			cin >> v;
			g[u-1].push_back(v-1);
		}
	}

	int t=1;
	for(int i=0;i<n;i++){
		if(!used[i]){
			t = dfs(i,t);
		}
	}

	for(int i=0;i<n;i++){
		cout << i+1 << " " << ans[i][0] << " " << ans[i][1] << "\n";
	}

	return 0;
}

C++: #include <bits/stdc++.h>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

int n;
int u, k, v;
int hour = 1;
int d[101] = {}, f[101] = {};
int gra[101][101] = {};
int color[101] = {};


void dfs(int u) {
	color[u] = 1;
	d[u] = hour;
	hour++;
	FOR(i, 1, n) {
		if (gra[u][i] == 1 && color[i] == 0) {
			dfs(i);
		}
	}
	color[u] = 2;
	f[u] = hour;
	hour++;
}


int main(void) {
	cin >> n;
	
	FOR(i, 1, n) {
		cin >> u >> k;
		FOR(t, 1, k) {
			cin >> v;
			gra[u][v] = 1;
		}
	}
	d[1] = hour;

	dfs(1);

	FOR(i, 1, n) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>

int main(){
    int n;
    scanf("%d",&n);
    int a[n+1][n+1];
    int i,j;
    for(i=1;i<=n;i++)for(j=1;j<=n;j++)a[i][j]=0;
    for(i=1;i<=n;i++){
        int q,k;
        scanf("%d %d",&q,&k);
        for(j=1;j<=k;j++) {
            int p;
            scanf("%d",&p);
            a[q][p]=1;
        }
    }
    int time=0;
    std::stack<int>S;
    int ans[n+1][3];
    
    
    
    S.push(1);
    time++;
    ans[1][1]=time;
    
    int color[n+1];
    color[1]=1;
    for(i=2;i<=n;i++)color[i]=0;//0??????????¨????
    int lastcheck=0;
    
    while(lastcheck==0){
    while(S.size()>=1){
        int flag=0;//flag=0??????pop
        for(i=1;i<=n;i++){
            if(i!=S.top()&& a[S.top()][i]==1 &&color[i]==0){
                S.push(i);
                color[i]=1;
                time++;
                ans[i][1]=time;
                flag=1;
                break;
            }
        }
        if(flag==0){
            time++;
            ans[S.top()][2]=time;
            S.pop();
        }
    }
        lastcheck=1;
        for(i=1;i<=n;i++)if(color[i]==0){
            lastcheck=0;
            break;
        }
        S.push(i);
        time++;
        ans[i][1]=time;
        
    }
    for(i=1;i<=n;i++){
        printf("%d %d %d\n",i,ans[i][1],ans[i][2]);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int n, m[100][100] = { 0 }, d[100] = { 0 }, t = 0, nt[100] = { 0 }, f[100] = { 0 };
int color[100] = { WHITE };

int next(int u) {
	FOR(i, nt[u], n) {
		nt[u] = i + 1;
		if (m[u][i]==1){ return i; }
	}
	return -1;
}

int dfs(int r) {
	stack<int>S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++t;

	while (!S.empty()) {
		int u=S.top();
		int v = next(u); //cout << v << endl;
		if (v != -1) {
			if (color[v]==WHITE)
			{
				S.push(v);
				color[v] = GRAY;
				d[v] = ++t;
			}
		}
		else {
			S.pop();
			color[v] = BLACK;
			f[u] = ++t;
		//	cout << f[v]<<endl;
		}
	}
	return 0;
}
int main()
{
	 cin >> n;
	REP(i, n) {
		int u, k; cin >>u >> k; u--;//
		REP(j, k) {
			int muki; cin >> muki; muki--;//
			m[u][muki] = 1;
			//printf("%d aa%d\n", u, muki);
		}
	}
	REP(i, n) {
		if (color[i] == WHITE) {
			dfs(i);// cout << i << endl;
		}
	}
	REP(i, n) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}