Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

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

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstring>
using namespace std;

bool A[110][110],flag[110];
int in[110],out[110];
int n,now=1;
stack<int> S;

void dfs_visit(int u){
	flag[u]=true;
	for(int i=1;i<=n;i++){
		if(A[u][i]==true && flag[i]==false) {
			S.push(i);
			in[i]=now++;
			dfs_visit(i);
		}
	}
	int x=S.top();
	S.pop();
	out[x]=now++;
	return ;
}

void dfs(){
	S.push(1);in[1]=now++;
	while(S.empty()==0){
		int x=S.top();
		dfs_visit(x);
		
	}
	for(int i=1;i<=n;i++) cout<<i<<" "<<in[i]<<" "<<out[i]<<endl;
	return ;
}

int main (){
	int a,b,c;
	cin>>n;
	for(int i=1;i<=n;i++){
		flag[i]=false;
			for(int j=1;j<=n;j++){
				A[i][j]=false;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		for(int j=1;j<=b;j++){
			cin>>c;
			A[a][c]=true;
		}
	}
	dfs();
	return 0;

}