Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;

short d[101] = {}, v[101] = {};
bool  p[101][101] = {};
short t = 0;
int n;  

void dfs(int i) {
    if(d[i] != 0) return;
    d[i] = ++t;
    rep(j,n+1) {
        if(p[i][j] == 1 & d[j] == 0) {
            dfs(j);     
        }
    }
    v[i] = ++t;
}

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

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

int n;
int x[101][101];
int color[101], a[101], b[101];
int t;

void  DFS_VISIT(int u) {
	color[u] = 1;
	a[u] = ++t;
	for (int v = 0;v < n;v++) {
		if (x[u][v] == 0) {
			continue;
		}
		if (color[v] == 0) {
			DFS_VISIT(v);
		}
	}
		color[u] = 2;
		b[u] = ++t;

}

void DFS() {
	for (int u = 0;u < n;u++) {
		color[u] = 0;
	}
	t = 0;
	for (int u = 0;u < n;u++) {
		if (color[u] == 0) {
			DFS_VISIT(u);
		}
	}
	for (int u = 0;u < n;u++) {
		cout << u + 1<<" " << a[u]<<" " << b[u] << endl;;
	}
}

int main() {
	cin >> n;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) {
			x[i][j] = 0;
		}
	}
	int u, k, v;
	for (int i = 0;i < n;i++) {
		cin >> u >> k;
		u = u - 1;
		for (int j = 0;j < k;j++) {
			cin >> v;
			v = v - 1;
			x[u][v] = 1;
		}
	}

	DFS();

	return 0;
}

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

int n, t;
int v[100][100];
int d[100], f[100];

void stamp(int id) {
	if (t > 2 * n)
		return;

	if (d[id - 1] == 0) {
		d[id - 1] = t;
		t++;
		int i = 0;
		while (v[id - 1][i] == 0)
			i++;
		if (i < n && d[i] == 0)
			stamp(i + 1);
		else
			stamp(id);
	}
	else if (f[id - 1] == 0) {
		f[id - 1] = t;
		t++;

		int i = id - 1;
		while (d[i] != 0)
			i++;
		if (i < n)
			stamp(i + 1);
		else {
			int i = n - 1;
			while (v[i][id - 1] == 0)
				i--;
			stamp(i + 1);
		}
	}
	else
		return;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		d[i] = 0;
		f[i] = 0;
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			v[i][j] = 0;

	for (int i = 0; i < n; i++) {
		int u, k, s;

		cin >> u >> k;

		for (int j = 0; j < k; j++) {
			cin >> s;
			v[u - 1][s - 1] = 1;
		}
	}

	t = 1;
	stamp(1);

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

	return 0;
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C
#include <iostream>
#include <cstdio>
#include <queue> // 入れた順番に出していく玉突き構造。
using namespace std;

int G[110][110];
int n;
int u, k, v;

/* void print_matrix(int N) {
  for(int i=0; i<N; i++) {
    for(int j=0; j<N; j++) {
      printf("%d", G[i][j]);
      if (j < N-1) {
	printf(" ");
      }
    }
      printf("\n");
  }
} */

void make_matrix() {
  fill(&G[0][0], &G[0][0]+110*110, 0);
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf("%d%d", &u, &k);
    u--;
    for (int j=0; j<k; j++) {
      scanf("%d", &v);
      v--;
      G[u][v] = 1;
    }
  }
}

int timer = 1; // timeだとエラーが出たので。
int d[110]; // 訪問時刻。ナマの数字を入れる。
int f[110]; // 終了時刻。ナマの数字を入れる。

void init() {
  fill(d, d+110, -1);
  fill(f, f+110, -1);
}

void dfs(int cur) { // curを訪問。
  d[cur] = timer;
  timer++;
  // cerr << "visiting " << cur << " at the time " << timer << endl;
  for (int i=1; i<=n; i++) { // 節点i
    if (G[cur-1][i-1] == 1 && d[i] == -1) {
      dfs(i);
    }
  }
  f[cur] = timer;
  timer++;
}

int main() {
  make_matrix();
  init();
  dfs(1);
  for (int i=1; i<=n; i++) {
    printf("%d %d %d\n", i, d[i], f[i]);
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int	dfs(const Graph &graph,
		vector<int> &d_vec, vector<int> &f_vec, int u, int cur_time)
{
	d_vec.at(u) = ++cur_time;
	for (int v : graph.at(u)) {
		if (d_vec.at(v) != -1)
			continue;
		cur_time = dfs(graph, d_vec, f_vec, v, cur_time);
	}
	f_vec.at(u) = ++cur_time;
	return cur_time;
}	
		
int	main()
{
	int	n;
	cin >> n;
	Graph graph(n);
	vector<int>	d_vec(n, -1);
	vector<int>	f_vec(n, -1);
	int	k;
	int	u, v;
	for (int i = 0; i < n; ++i) {
		cin >> u >> k;
		--u;
		for (int j = 0; j < k; ++j) {
			cin >> v;
			--v;
			graph.at(u).push_back(v);
		}
	}
	int cur_time = 0;
	for (int i = 0; i < n; ++i) {
		if (d_vec.at(i) != -1)
			continue;
		cur_time = dfs(graph, d_vec, f_vec, i, cur_time);
	}
	for (int i = 0; i < n; ++i) {
		cout << i + 1 << " " << d_vec.at(i) << " " << f_vec.at(i) << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
const int MAX=100;
const int WHITE=0;
const int GRAY=1;
const int BLACK=2;
using namespace std;
int M[MAX][MAX],d[MAX],f[MAX],tt,n,color[MAX];

void dfs_visit(int i){
    color[i]=GRAY;
    d[i]=++tt;
    for(int u=0;u<n;u++){
        if( M[i][u]==0)continue;
        dfs_visit(u);
    }
    color[i]=BLACK;
    f[i]=++tt;
}





void dfs(){
    int i;
    for(i=0;i<n;i++){
        color[i]=0;
    }
    tt=0;
    for(i=0;i<n;i++){
        if( color[i]==WHITE)dfs_visit(i);
    }
    for(i=0;i<n;i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}
int main(){
  //  cout<<"A"<<endl;
    cin>>n;
    int u,v,k;
    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;
}