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<iostream>
#include<cstdio>
#define M 100
#define G -1
#define B -2
#define W 0
using namespace std;

int n,T = 0;
int A[M+1][M+1],t[M+1][2],color[M+1];

void white(){
    for(int i = 0; i <= n;i++) color[i] = W;
}

void DFS(int x){
    T++;
    color[x] = G;
    t[x][1] = T;
    for(int i = 1; i <= n; i++){
        if(A[x][i] == 0) continue;
        else if(color[i] == W){
            DFS(i);
        }
    }
    T ++;
    color[x] = B;
    t[x][2] = T; 
}

int main(){
    int u,k,v;
    scanf("%d",&n);
    for(int i = 0; i <= n; i++){
        for(int j =0 ; j <= n; j++) A[i][j] = 0;
    }
    for(int i = 1; i <= n; i++){
        scanf("%d %d",&u,&k);
        for(int j = 0; j < k; j++){
            scanf("%d",&v);
            A[u][v] = 1;
        }
    }
    
    white();
    for(int i = 1; i <= n; i ++){
        if(color[i] == W) DFS(i);
    }
    
    for(int i = 1; i <= n; i++) printf("%d %d %d\n",i,t[i][1],t[i][2]);
    
    return 0;
}

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

const int N = 100;
int M[N][N];
int n;
int t;
int color[N];
int d[N], f[N];

void init(){
  for(int i=0;i<n;i++){
    color[i] = 0;
  }
}

void dfs(int x){
  color[x] = 1;
  d[x] = ++t;
  for(int i=0;i<n;i++){
    if(M[x][i] == 1 && color[i] == 0){
      dfs(i);
    }
  }
  color[x] = 2;
  f[x] = ++t;
}

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

C++: #include <iostream>

using namespace std;

#define N_MAX 100

int Adj[N_MAX][N_MAX] = {};
int Chk[N_MAX][2] = {};
int search_time = 1;

void dfs(int v, int num_node);

int main()
{
    int n, i, u, k, v, j;

    cin >> n;

    //??£??\???????????????
    for (i = 0; i < n; i++) {
        cin >> u >> k;
        while (k-- > 0) {
            cin >> v;
            Adj[u-1][v-1] = 1;
        }
    }
/*
    cout << "show Adjacency matrix" << endl;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n ; j++) {
            if (j == n - 1)
                cout << Adj[i][j] << endl;
            else
                cout << Adj[i][j] << ' ';
        }
    }
*/
    //??¢?´¢??????
    dfs(1, n);

    for(i = 0; i < n; i++) {
        cout << i+1 << ' ' << Chk[i][0] << ' ' << Chk[i][1] << ' ' <<  endl;
    }

    return 0;
}

void dfs(int v, int num_node) {

//    cout << "dfs node : " << v << " time : " << search_time << endl;

    int i;
    //v???????????????????¨????
    if (Chk[v-1][0] == 0) //????????????node?????´???
        Chk[v-1][0] = search_time++;
    else {                //??¢??\???node?????´???
    //    search_time++;
        return;
    }

    //v???????????¢?´¢
    for (i = 1; i <= num_node; i++) {
        if (Adj[v-1][i -1] == 1) {
            dfs(i, num_node);
        }
    }

    //?????±??¨?????§??¢?´¢??????????????????
    //v???????????????????¨????
    Chk[v-1][1] = search_time++;
}

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 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<iostream>
#include<vector>
using namespace std;

struct Tree
{
    int p, start, end;
    bool isSearched;
    vector<int> v;
};

void DFS( Tree* t, int a, int& cnt )
{
    if( t[a].isSearched )
        return;

    t[a].isSearched = true;

    cnt++;
    t[a].start = cnt;

    for( int i = 0; i < t[a].v.size(); i++ )
        DFS( t, t[a].v[i], cnt );

    cnt++;
    t[a].end = cnt;
}


int main()
{
    int n, a, b, c;
    Tree t[101];

    for( int i = 0; i < 101; i++ )
    {
        t[i].p = -1;
        t[i].isSearched = false;
    }
    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> a >> b;
        for( int j = 0; j < b; j++ )
        {
            cin >> c;
            t[a].v.push_back(c);
            t[c].p = a;
        }
    }

    int cnt = 0;
    for( int i = 1; i <= n; i++ )
            DFS( t, i, cnt );

    for( int i = 1; i <= n; i++ )
        cout << i << " " << t[i].start << " " << t[i].end << endl;

    return 0;
}