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;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;
int n,v[100+1][100+1]={},color[100+1]={},tim,d[1000],f[1000];
void visit(int u){
  color[u]=1;
  d[u]=++tim;
  rep(i,n){
    if(v[u][i]==0)continue;
    if(color[i]==0)
      visit(i);
  }
  color[u]=2;
  f[u]=++tim;
}
void dfs(){
  rep(i,n)color[i]=0;
  tim = 0;
  rep(i,n){
    if(color[i]==0)
      visit(i);
  }
}

int main(){
  cin>>n;
  int u,k,in;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>in;
      v[u-1][in-1]=1;
    }
  }
  dfs();
  rep(i,n)cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

stack<int> S;
int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N]; //未訪問な次の頂点を保持

//未訪問な次の頂点を返す．全て訪問済みなら-1を返す
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 i){
    S.push(i);
    color[i] = GRAY;
    d[i] = ++tt;

    while(!S.empty()){
        int u = S.top();
        int v = next(u);
        if(v != -1){
            if(color[v] == WHITE){
                S.push(v);
                color[v] = GRAY;
                d[v] = ++tt;
            }
        }else{
            color[u] = BLACK;
            f[u] = ++tt;
            S.pop();
        }
    }
}

void dfs(){
    for(int i = 0; i < n; i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    for(int i = 0; i < n; i++){
        if(color[i] == WHITE) dfs_visit(i);
    }

    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--; //0オリジンに変換
        for(int j = 0; j < k; j++){
            cin >> v;
            v--; //0オリジンに変換
            M[u][v] = 1;
        }
    }

    dfs();
    
    return 0;

}

C++: //Shunji Lin 08-144505

#include <iostream>

using namespace std;

bool adjmatrix[101][101]; //adjmatrix
int discover[101];
int processed[101];
int cur_time = 0;


void DFS(int vertex, int N) {
  cur_time++;
  discover[vertex] = cur_time; // set cost
  
  for (int i =1; i<= N; i++) {
    if(adjmatrix[vertex][i] && discover[i] == -1) {
      DFS(i, N);
    }
  }
  
  cur_time++;
  processed[vertex] = cur_time;
}


  
int main() {
  const int cur_time = 0;
  
  for (int i = 0; i < 101; i++) {
    discover[i] = -1; // upper limit
    processed[i] = -1;
  }
  int N;
  cin >> N;

  for (int i = 1; i <= N; i++) {
    int vertex, degree;
    cin >> vertex >> degree;

    for (int j = 0; j < degree; j++) {
      int outvertex;
      cin >> outvertex;
      adjmatrix[i][outvertex] = true;
    }
  }

  
  

  DFS(1,N);


  for (int i = 1; i <=N; i++) {
    if (discover[i] != -1) {
      cout << i << " " << discover[i] << " "<< processed[i] << endl;
    }
  }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define vector_rsort(x) sort(all(x));reverse(all(x))
#define array_rsort(x,n) sort(x,x+n);reverse(x,x+n);
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int n,t=1;
int d[105],f[105];
int used[105];
vi g[105];

void init(){
  rep(i,105){
    d[i]=f[i]=INF;
  }
}

void dfs(int now){
  d[now]=min(d[now],t);
  rep(i,g[now].size()){
    if(!used[g[now][i]]){
      used[g[now][i]]=true;
      t++;
      dfs(g[now][i]);
    }
  }
  t++;
  f[now]=min(f[now],t);
}

int main(){
  int u,k,v;
  cin>>n;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>v;
      g[u].pb(v);
    }
  }
  init();
  dfs(1);
  REP(i,1,n+1){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
}