Go: package main

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

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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