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 n, tt;
int M[N][N], color[N], d[N], f[N], 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] = 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 {
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


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

int main() {
	int k , u, 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 i = 0; i < k; i++) {
	        cin >> v;
	        v--;
		   M[u][v] = 1; 
     	}
	} 
	
	dfs();
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX=101;
bool Visited[MAX]; //??\?????????????¢??????????
vector<int> Adjacency[MAX];
int dTime[MAX]; int fTime[MAX]; //?¢??????°??¶??´????¢?????????¶??´
void dfs(int j,int clock)
{

    stack<int> S;
    S.push(j);dTime[j]=++clock;
    Visited[j]=true;
    while(!S.empty())
    {
        int p=S.top(); //???????????¶??????
        if(Adjacency[p].size()==0)
        {
            S.pop();
            fTime[p]=++clock;
            continue;
        }
        int i=0;
        if(Adjacency[p].size())
          while(Visited[Adjacency[p][i]]==true)
          {
            i++;
            if(i==Adjacency[p].size()) //???????°??????????????±?????????????
            {
                S.pop();
                fTime[p]=++clock;
                break;
            }
          }
        if(i==Adjacency[p].size()) continue;
        //if founded
        S.push(Adjacency[p][i]); dTime[Adjacency[p][i]]=++clock;
        Visited[Adjacency[p][i]]=true;
    }
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) Visited[i]=false;

    for(int i=1;i<=n;i++)
    {
        int p;cin>>p;
        int num;
        cin>>num;

        for(int j=0;j<num;j++)
        {
            int t;
            cin>>t;
            Adjacency[p].push_back(t);
        }
    }
    int clock=0;
    for(int i=1;i<=n;i++)  //???????????????????????°DFS?£?????????????
    {
        if(Visited[i]==false) dfs(i,clock);
    }
    for(int i=1;i<=n;i++)
        cout<<i<<' '<<dTime[i]<<' '<<fTime[i]<<endl;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;
using Graph = vector<vector<int>>;

// 難しいね
int main()
{
    // input
    int n;
    cin >> n;
    vector<queue<int>> q(n+1);
    rep2(i,1,n+1){
        int id, num;
        cin >> id >> num;
        rep(j,num){
            int temp;
            cin >> temp;
            q[i].push(temp);
        }
    }


    // solve
    vector<int> d(n+1), f(n+1);
    stack<int> place;
    place.push(1);
    int time = 0;
    while(place.size()){
        int now = place.top();
        if(!d[now]) d[now] = ++time;

        while(q[now].size()){
            if(!d[q[now].front()]){
                place.push(q[now].front());
                q[now].pop();
                break;
            }else{
                q[now].pop();
            }
        }
        if(now == place.top()){
            place.pop();
            f[now] = ++time;
        }
        if(place.size() == 0){
            rep2(i,1,n+1){
                if(d[i]==0){place.push(i); break;}
            }
        }
    }

    // output
    rep2(i,1,n+1) cout << i << " " << d[i] << " " << f[i] << endl;
    return 0;
}

C++: #include <iostream>

using namespace std;

#define N_MAX 100

int Adj[N_MAX][N_MAX] = {};
int Chk[N_MAX][2] = {};
int search_time = 1;

void dfs(int v, int num_node);

int main()
{
    int n, i, u, k, v, j;

    cin >> n;

    //??£??\???????????????
    for (i = 0; i < n; i++) {
        cin >> u >> k;
        while (k-- > 0) {
            cin >> v;
            Adj[u-1][v-1] = 1;
        }
    }
/*
    cout << "show Adjacency matrix" << endl;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n ; j++) {
            if (j == n - 1)
                cout << Adj[i][j] << endl;
            else
                cout << Adj[i][j] << ' ';
        }
    }
*/
    //??¢?´¢??????
//    dfs(1, n);
    for (i = 1; i <= n; i++) {
        if (Chk[i-1][0] == 0)
            dfs(i, n);
    }

    for(i = 0; i < n; i++) {
        cout << i+1 << ' ' << Chk[i][0] << ' ' << Chk[i][1] << ' ' <<  endl;
    }

    return 0;
}

void dfs(int v, int num_node) {

//    cout << "dfs node : " << v << " time : " << search_time << endl;

    int i;
    //v???????????????????¨????
    if (Chk[v-1][0] == 0) //????????????node?????´???
        Chk[v-1][0] = search_time++;
    else {                //??¢??\???node?????´???
    //    search_time++;
        return;
    }

    //v???????????¢?´¢
    for (i = 1; i <= num_node; i++) {
        if (Adj[v-1][i -1] == 1) {
            dfs(i, num_node);
        }
    }

    //?????±??¨?????§??¢?´¢??????????????????
    //v???????????????????¨????
    Chk[v-1][1] = search_time++;
}