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++: #include<iostream>
#include<stack>
using namespace std;
static const int N = 100; 
static const int WHITE = 0;
static const int GRAY = 1; 
static const int BLACK = 2;

int M[N][N], color[N], d[N], f[N], nt[N];
int tt,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 u) {
	for(int i = 0; i < n; i++) nt[i] = 0;
	
	stack<int> S;
	S.push(u);
	color[u] = BLACK;
	d[u] = ++tt;
	
	while(!S.empty()) {
		int u = S.top();
		int v = next(u);
		if(v != -1) {
			if(color[v] == WHITE) {
			   color[v] = GRAY;
			   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; 
	}
	tt = 0; 
	
	for(int j = 0; j < n; j++) {
		if(color[j] == WHITE) {
			dfs_visit(j);
		}
	}
	
	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;
      }	
	}
	cin >> u >> k ;
	u--;
	for(int i = 0; i < k; i++ ) {
	   cin >> v;
	   v--;
	   M[u][v] = 1;	
	}	
	
	dfs();
	
	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;
        }
        if(lastcheck==0){
            S.push(i);
            time++;
            ans[i][1]=time;
            color[i]=1;
        }
    }
    
    
    for(i=1;i<=n;i++){
        printf("%d %d %d\n",i,ans[i][1],ans[i][2]);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <climits>
using namespace std;

#define MAX_N 101

int n, t;
vector<vector<int> > A(MAX_N, vector<int>(MAX_N, 0));
stack<int> S;
int d[MAX_N] = {};
int f[MAX_N] = {};

void df(int e)
{
    d[e] = ++t;
    for (int i = 1; i <= n; i++) {
        if (A[e][i] && !d[i]) df(i);
    }
    f[e] = ++t;
}

int main()
{
    int i, u, k, v;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> u >> k;
        while (k--) {
            cin >> v;
            A[u][v]++;
        }
    }
    t = 0;
    df(1);
    for (i = 1; i <= n; i++)
        cout << i << " " << d[i] << " " << f[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 GRAY=1;//訪問した頂点
static const int BLACK=2;//２度目の訪問になる頂点

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

//uに隣接するvを番号順に取得
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]=GRAY;
    d[r]=++tt;//ｒ頂点の発見時刻
    
    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1){
            if(color[v]==WHITE){
                color[v]=GRAY;
                d[v]=++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u]=BLACK;
            f[u]=++tt;//u頂点の終了時刻
        }
    }
}

void dfs(){
    //初期化
    for (int i=0; i<n; i++){
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;
    
    //未訪問のuを始点として深さ優先探索
    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;
}