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>

using namespace std;
int n,u,k,v,**M,flag[100],s_time[100],f_time[100];
void creat()
{
    cin>>n;
  M=new int*[n];
  for(int i=0;i<n;i++)
    {
      M[i]=new int[n];
      flag[i]=0;
      for(int j=0;j<n;j++)
	M[i][j]=0;
    }
  int count=0;
  while(count<n)
    {
      count++;
      cin>>u>>k;
      for(int i=0;i<k;i++)
	{
	  cin>>v;
	  M[u-1][v-1]=1;
	}
    }
    /*for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)
      cout<<M[i][j]<<' ';
    cout<<endl;
  }*/
}
int time = 0;
void dfs(int cur) {
    time += 1;
    s_time[cur]=time;
    //cout << "visiting " << cur+1 << ' ' << time << endl;
    flag[cur]=1;
    for (int dst=0;dst<n;dst++) {
            if (M[cur][dst]&&!flag[dst]) {
                dfs(dst);
            }
    }
    time += 1;
    f_time[cur]=time;
}
int main()
{
    creat();
    for(int i=0;i<n;i++)
    {
        if(!flag[i])
            dfs(i);
    }
    for(int i=0;i<n;i++)
    {
        cout<<i+1<<' '<<s_time[i]<<' '<<f_time[i]<<endl;
    }
    delete M;
    return 0;
}

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

typedef long long llint;
typedef long double ld;
typedef pair<int,int> P;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)


priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


#define N 100

int g[N][N];
int d[N];
int f[N];
int t=0;


bool flag[N];
int n;

void dfs(int i){
    flag[i]=true;
    d[i]=++t;
    rep(j,0,n){
        if(g[i][j]==1 && !flag[j]){
            dfs(j);
        }
    }
    f[i]=++t;
}

void solve(){
    cin >> n;
    int u,k;
    rep(i,0,n){
        cin >> u >> k;
        u--;
        rep(j,0,k){
            int v;
            cin >> v;
            v--;
            g[u][v]=1;
        }
    }
    rep(i,0,n){
        if(!flag[i]){
            dfs(i);
        }
    }
    rep(i,0,n){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main(){
    solve();
    return 0;
}

C++: 
#include <iostream>

using namespace std;

int d[100]={0},f[100]={0};
int k[101],v[101][100],n;
int c;
void solve();
void dfs(int point);

int main()
{
	cin>>n;
	for (int i=0; i<n; i++) {
		int t;
		cin>>t;
		cin>>k[t];
		for (int j=0; j<k[t]; j++) {
			cin>>v[t][j];
		}
	}
	solve();
}

void solve() {
	d[1]=1,c=2;
	for (int i=0; i<k[1]; i++) {
		if (d[v[1][i]]==0) {
			dfs(v[1][i]);
		}
	}
	c++;
	f[1]=c;
	for (int i=0; i<n; i++) {
		cout<<i+1<<' '<<d[i+1]<<' '<<f[i+1]<<endl;
	}
}
void dfs(int point)
{
	d[point]=c;
	int i=0;
	c++;
	while (i<k[point]) {
		if (d[v[point][i]]==0) {
			dfs(v[point][i]);
			c++;
		}
		i++;
	}
	if (f[point]==0) {
		f[point]=c;
	}
}

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

using namespace std;
int d[100],f[100];
int M[100][100];
int n,t=0;

void dfs(int s){
    stack<int> S;
    int u;
    bool found=0;
    
    S.push(s);
    d[s]=++t;
    while( !S.empty() ){
	u=S.top();
	found=0;
	for(int v=0;v<n;v++){
	    if(M[u][v]==1 && d[v]==0){
		S.push(v);
		d[v]=++t;
		found=1;
		break;
	    }
	}
	if(found==0){
	    S.pop();
	    f[u]=++t;
	}
    }
}
    
int main(){
    int u,k,v;

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

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

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

    return 0;
}

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

using namespace std;



int n;
int u[102], k[102],  v[102][102];
int timecount = 0;
int time_keep[102][2];
bool visited[102];
vector<int> vertices[100+5];
bool check(int& remain, int N);


void dfs(int cur){
	visited[cur] = true;
	// cur の訪問時刻を記録
	timecount += 1;
	int e = timecount;
	// 動作確認用表示
	//cerr << "visiting " << cur <<" " << timecount << endl;
	
	//cout << cur + 1 << " " << timecount << " ";
	
	for(auto itr = vertices[cur].begin(); itr!=vertices[cur].end(); itr++){
        if(!visited[*itr]){
            dfs(*itr);
            visited[*itr] = true;
        }
    }
     
	/*
	for(int dst = 0; dst < n; ++dst){
		//timecount1 += 1;
		if(visited[dst] == false){
			dfs(dst);
			visited[dst] = true;
		}
	}
	*/
	
	// cur の訪問終了時刻を記録
	timecount += 1;
	int f = timecount;
	time_keep[cur][0] = e;
	time_keep[cur][1] = f;
	//cout << cur + 1 << " " << e << " " << timecount << endl;
	//cout << timecount << endl;
	// 関数の終わりで親に戻る(青矢印)
}

bool check(int& remain, int N){
    for(int i = 1; i <= N; ++i){
        if(!visited[i]) {
            remain = i;
            //cout << "remain:" << remain  << endl;
            return false;
        }
    }
    return true;
}

int main(){
	cin >> n;
	/*
	for(int i = 0; i < n; ++i){
		cin >> u[i] >> k[i];
		for(int j = 0; j < k[i]; ++j){
			cin >> v[i][j];
			//cout << D[i][j] << endl;
		}
	}
	*/
	for(int i = 0; i < n; ++i){
        int index, itr;
        cin >> index >> itr;
        for(int i = 0; i < itr; ++i) {
            int buff;
            cin >> buff;
            vertices[index].push_back(buff);
        }
    }

	dfs(1);
	int remain;
	//for(int i = 0; i < n; ++i){
	//	dfs(i);
	//}
	while(!check(remain, n)){//未発見のものがないか?
        //cout << "DETECTED" << endl;
        dfs(remain);
    }

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

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

#define N 100

int A[N + 1][N + 1] = {};
int n, u, k, v;
int t = 1; //tは時間
int t1[N + 1] = {}; //発見時刻
int t2[N + 1] = {}; //終了時刻

//sは始点
void dps(int s) {
    t1[s] = t;
    for(int a = 1; a <= n; ++a) A[a][s] = 0;
    for(int i = 1; i <= n; ++i) {
        if(A[s][i] == 1) {
            ++t;
            dps(i);
        }
    }
    ++t;
    t2[s] = t;
    
}

int main(void) {
    cin >> n;
    
    for(int i = 0; i < n; ++i) {
        cin >> u >> k;
        for(int j = 0; j < k; ++j) {
            cin >> v;
            A[u][v] = 1;
        }
    }
    
    for(int i = 1; i <= n; ++i) {
        if(t2[i] == 0) {
            dps(i);
            ++t;
        }
    }
    
    for(int i = 1; i <= n; ++i) {
        cout << i << ' ' << t1[i] << ' ' << t2[i] << endl;
    }
    
    
    return 0;
}