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 <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define vector_rsort(x) sort(all(x));reverse(all(x))
#define array_rsort(x,n) sort(x,x+n);reverse(x,x+n);
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int n,t=1;
int d[105],f[105];
int used[105];
vi g[105];

void init(){
  rep(i,105){
    d[i]=f[i]=INF;
  }
}

void dfs(int now){
  d[now]=min(d[now],t);
  rep(i,g[now].size()){
    if(!used[g[now][i]]){
      used[g[now][i]]=true;
      t++;
      dfs(g[now][i]);
    }
  }
  t++;
  f[now]=min(f[now],t);
}

int main(){
  int u,k,v;
  cin>>n;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>v;
      g[u].pb(v);
    }
  }
  init();
  REP(i,1,n+1)dfs(i);
  REP(i,1,n+1){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int a[105][105];
pair<int,int> ans[105];
int co;
int n;
void dfs(int x){
  if(ans[x].first==0){
    co++;
    ans[x].first = co ;
  }
  else return;
  //cout << n << endl;
  for(int i=1;i<=n;i++){
    //cout << a[x][i]<<endl;
    if(a[x][i]==1)dfs(i);
  }
  if(ans[x].second==0){
    co++;
    ans[x].second=co;
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    int u,m;
    cin >> u >> m;
    for(int j=0;j<m;j++){
      int v;
      cin >> v;
      a[u][v]=1;
    }
  }
  for(int i=1;i<=n;i++){
    dfs(i);
  }
  for(int i=1;i<=n;i++){
    cout << i << " " << ans[i].first << " "<< ans[i].second << endl;
  }
  return 0;
}

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

/* constant */

const int MAX_N = 100;

/* typedef */

typedef vector<int> vi;

/* global variables */

vi nbrs[MAX_N];
int ds[MAX_N], fs[MAX_N];

/* subroutines */

int dfs(int u, int t) {
  ds[u] = ++t;

  for (int i = 0; i < nbrs[u].size(); i++) {
    int &v = nbrs[u][i];
    if (! ds[v]) t = dfs(v, t);
  }

  return (fs[u] = ++t);
}

/* main */

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

  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    u--;

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

  int t = 0;
  for (int i = 0; i < n; i++)
    if (! ds[i]) t = dfs(i, t);

  for (int i = 0; i < n; i++)
    printf("%d %d %d\n", i + 1, ds[i], fs[i]);

  return 0;
}

C++: #include<iostream>
#include<cstdio>
#define N 101
using namespace std;

int g[N][N]; 
int d[N];
int f[N];
int n;
int times=0;
bool us[N];

//dfs
void dfs(int x){
  
  times++;
  d[x]=times;

  for(int i=1;i<=n;i++){
    if(g[x][i]==1 &&us[i]==false){
      us[i]=true;
      // cout <<"i "<<i<<endl;
      dfs(i);
    }
  } 
  f[x]=times=times+1;

}


int main(){
  
  int n2,data,u;

  //load n
  cin >>n;
  
  //initialize
  for(int i=0;i<N;i++){
    us[i]=false;
    for(int j=0;j<N;j++){
      g[i][j]=0;
    }
  }
  
  //load data
  for(int i=0;i<n;i++){
    scanf("%d%d",&u,&n2);
    for(int j=0;j<n2;j++){
      scanf("%d",&data);
      g[u][data]=1;
    }
  }
  
  //execute
  dfs(1);

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

C++: #include <bits/stdc++.h>
#define ll long long
using namespace std;

struct ver{
    ll d;
    ll f;
};

ll t=0;
vector<vector<ll>> mat;
vector<ver> vers;

void find(ll pos) {
    if(vers[pos].d == 0){
        t++;
        vers[pos].d = t;
        for(ll i:mat[pos]) {
            find(i);
        }
        if(vers[pos].f == 0) {
            t++;
            vers[pos].f = t;
        }
    }
}

int main() {
    ll n;
    cin >> n;
    for(ll i=0;i<n;i++) {
        ll u,k;
        cin>>u>>k;
        vector<ll> aaa;
        for(ll j=0;j<k;j++) {
            ll tmp;
            cin>>tmp;
            aaa.push_back(tmp-1);
        }
        mat.push_back(aaa);
    }
    for(ll i=0;i<n;i++) {
        vers.push_back(ver{0,0});
    }
    for(ll i=0;i<n;i++) {
        if(vers[i].d == 0)find(i);
    }
    for(ll i=0;i<n;i++) {
        cout << i+1<<" "<<vers[i].d<<" "<<vers[i].f<<endl;
    }
}