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<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int n, t, d[101], f[101];
vector< vector<int> >m(101);


void dfs(int u){
    d[u] = ++t;
    int v;
    for(int i=0; i<m[u].size(); i++){
        v = m[u][i];
        if(d[v]==-1){
            dfs(v);
        }
    }
    f[u] = ++t;
    return;
}

int main(){
    //freopen("in.txt", "r", stdin);
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        int id, d, to;
        scanf("%d %d", &id, &d);
        for(int j=0; j<d; j++){
            scanf("%d", &to);
            m[id].push_back(to);
        }
    }
    memset(d, 255, sizeof(d));
    t = -0;

    for(int i=1; i<=n; i++){
        if(d[i]==-1)
            dfs(i);
    }
    for(int i=1; i<=n; i++){
        printf("%d %d %d\n", i, d[i], f[i]);
    }
    return 0;
}

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

/*
 * ref. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B
 */

using namespace std;

const int MAX_N = 100;

int n;
int d[MAX_N];
int f[MAX_N];
vector<int> adjlist[MAX_N];

int dfs(const int id, int timestamp) {
    if (d[id - 1] > 0) {
        return timestamp;
    }

    timestamp++;
    d[id - 1] = timestamp;
    for (int i = 0; i < (int) adjlist[id - 1].size(); i++) {
        timestamp = dfs(adjlist[id - 1][i], timestamp);
    }
    timestamp++;
    f[id - 1] = timestamp;

    return timestamp;
}

int main(void) {
    cin >> n;

    for (int i = 0; i < n; i++) {
        int id, m;
        cin >> id >> m;
        for (int j = 0; j < m; j++) {
            int x;
            cin >> x;
            adjlist[id - 1].push_back(x);
        }
    }

    int timestamp = 0;
    for (int i = 0; i < n; i++) {
        int id = i + 1;
        timestamp = dfs(id, timestamp);
    }

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

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
//void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


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

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

void dfs_visit(int u)
{
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	rep(v, n)
	{
		if (M[u][v] == 0) continue;
		if (color[v] == WHITE)
		{
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs()
{
	int u;
	
	for (u=0; u<n; u++) color[u] = WHITE;
	tt = 0;
	
	for (u=0; u<n; u++)
	{
		if (color[u] == WHITE) dfs_visit(u);
	}
	
	for (u=0; u<n; u++)
	{
		printf("%d %d %d\n", u + 1, d[u], f[u]);
	}
}


int main()
{
	int u, v, k, i, j;
	
	scanf("%d", &n);
	rep(i, n) rep(j, n) M[i][j] = 0;
	
	rep(i, n)
	{
		scanf("%d %d", &u, &k);
		u--;
		rep(j, k)
		{
			scanf("%d", &v);
			v--;
			M[u][v] = 1;
		}
	}
	
	dfs();
	
	return 0;
}

/*
void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}
*/


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

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

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

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

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

C++: #include<bits/stdc++.h>
using namespace std;
void func(int p);
int n;
int box[101][101];
int d[101];
int f[101];
int flg[101];
int t;
int main(void){
	int u,k,v;
	int i,j;
	cin>>n;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			box[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v;
			box[u][v]=1;
		}
	}
	t=0;
	for(i=1;i<=n;i++){
		if(!flg[i]){
			func(i);
		}
	}
	for(i=1;i<=n;i++)	cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}
void func(int p){
	int i;
	t++;
	d[p]=t;
	flg[p]=true;
	for(i=1;i<=n;i++){
		if(box[p][i]==1){
			if(!flg[i]){
				func(i);
			}
		}
	}
	t++;
	f[p]=t;
}

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

int g[101][101], d[101], f[101];

int dfs(int id, int t)
{
    if(d[id]) return t;
    d[id]=++t;
    int n=g[id][0];
    for(int i=1; i<=n; i++) {
        t=dfs(g[id][i], t);
    }
    f[id]=++t;
    return t;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        int id, k;
        cin>>id>>k;
        g[id][0]=k;
        for(int j=1; j<=k; j++) {
            cin>>g[id][j];
        }
    }
    dfs(1, 0);
    for(int i=1; i<=n; i++) {
        cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
    }
    return 0;
}