Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

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

using namespace std;

/*****************************************/
/*         Function prototype            */
/*****************************************/

vector<vector<int> > list_to_mat(vector<vector<int> >& adj);
void dump_mat( vector<vector<int> >& mat);
void dfs(vector<vector<int> >& adj_list, int now, vector<int>& d, vector<int>& f, int *t);
void dfs_mat(vector<vector<int> >& adj_mat, int now, vector<int>& d, vector<int>& f, int* t);
/*****************************************/
/*            Main Function              */
/*****************************************/


int main(){
  int n; cin >> n;

  vector<vector<int> > list(n+1);
  for(int i=0; i<n; i++){
    int u,k; cin >> u >> k;
    vector<int> tmp(k);
    for(int j=0; j<k; j++) cin >> tmp[j];
    sort(tmp.begin(),tmp.end());
    list[u] = tmp;
  }
  int t=1;
  vector<int> d(n+1,-1);
  vector<int> f(n+1,-1);
  /*
  vector<vector<int> > adj_mat = list_to_mat(list); 
  
  for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
      cout << adj_mat[i][j] << " ";
    }
    cout << endl;
    }*/

  //  dfs_mat(adj_mat,1,d,f,&t);
  for(int i=1; i<=n; i++)
    if(d[i] == -1)
      dfs(list,i,d,f,&t);
  
  for(int i=1; i<=n; i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
}



/*****************************************/
/*            Implimentation             */
/*****************************************/


void dfs_mat(vector<vector<int> >& adj_mat, int now, vector<int>& d, vector<int>& f, int* t){
  d[now] = *t;
  (*t)++;
  
  for(int i=1; i<adj_mat.size(); i++){
    if(adj_mat[now][i] == 1 && d[i] == -1)
      dfs_mat(adj_mat, i, d, f, t);
  }

  f[now] = *t;
  (*t)++;
  return ;
}


void dfs(vector<vector<int> >& adj_list, int now, vector<int>& d, vector<int>& f, int* t){
  d[now] = *t;
  (*t)++;
  
  for(auto v : adj_list[now]){
    if(d[v] != -1 || v == 0) continue;
    dfs(adj_list, v, d, f, t);
  }
  f[now] = *t;
  (*t)++;
  return ;
}


vector<vector<int> > list_to_mat(vector<vector<int> >& adj){
  const int mat_size = (int)adj.size();
  vector<vector<int> > ans(mat_size,vector<int>(mat_size,0));
  for(int i=0; i<mat_size; i++){
    for(int j=0; j<adj[i].size(); j++){
      ans[i][adj[i][j]] = 1;
      ans[adj[i][j]][i] = 1;
    }
  }
  return ans;
}


void dump_mat( vector<vector<int> >& mat){
  
  const int mat_size = (int)mat.size();
  for(int i=0; i<mat_size; i++){
    for(int j=0; j<mat[i].size(); j++){
      cout << mat[i][j];
      if(j!=mat[i].size()-1)
	cout << " ";
      else
	cout << "\n";
    }
  }
}

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

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

void dfs(int r, int n, int t) {
	d[r] = ++t;
	for (int i = 1; i <= n; i++) {
		if (A[r][i] == 1 && d[i] == 0) dfs(i,n,t);
	}
	f[r] = ++t;
	return;
}

int main() {
	int u, v, l,n,t;
	t = 0;
	cin >> n;

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

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			A[i][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++) {
		cin >> u >> l;
		for (int j = 0; j < l; j++) {
			cin >> v;
			A[u][v] = 1;
		}
	}

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

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

	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;

#define N_MAX 100

typedef struct _v {
    int k;
    int *v;
    int f;
    int l;
} Vertex;
Vertex Adj[N_MAX];

int t = 0;

void depth_search(int i) {
//    printf(" i %d\n", t);
    if (Adj[i].f == 0) {
        Adj[i].f = t;
//        printf("  Adj[%d] : k = %d f = %d\n", i, Adj[i].k, t);
    }
    else {
        t--;
        return;
    }

    for (int j = 0; j < Adj[i].k; j++) {
        t++;
//        printf("t:%d\n", t);
        depth_search(Adj[i].v[j]);
    }
    t++;
//    printf("t:%d\n", t);
    Adj[i].l = t;
//    printf(" Adj[%d].l = %d\n", i, Adj[i].l);
    return;
}

int main() {
    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        int k;
        cin >> k >> k;
        Adj[i].k = k;
        Adj[i].v = new int[k];
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            Adj[i].v[j] = v - 1;
        }
        Adj[i].f = 0;
        Adj[i].l = 0;
    }

    for (int i = 0; i < n; i++) {
        t++;
        depth_search(i);
        cout << i + 1 << " " << Adj[i].f << " " << Adj[i].l << endl;
    }

    return 0;
}

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

const int MAX = 110;
int mat[MAX][MAX];
int d[MAX], f[MAX];
int n, t;

void dfs(int i)
{
  if (d[i] != -1) return;
  d[i] = ++t;
  for (int j = 0; j < n; j++)
    if (mat[i][j])
      dfs(j);
  f[i] = ++t;
}

int main()
{
  cin >> n;
  memset(mat, 0, sizeof(mat));
  for (int i = 0; i < n; i++) {
    int u; cin >> u; u--;
    int k; cin >> k;
    for (int j = 0; j < k; j++) {
      int v; cin >> v; v--;
      mat[u][v] = 1;
    }
  }
  memset(d, -1, sizeof(d));
  t = 0;
  for (int i = 0; i < n; i++)
    dfs(i);

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