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 <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
#include <list>
using namespace std;

int n;

struct Node{
public:
  int id, d, f, flag;
  vector<int> c;
  Node(){d = 1000000007;f = flag = 0;}
};

vector<Node> v(101);

void rec(int id, int &t){
  if(v[id].flag)return;
  else          v[id].flag = 1;
  v[id].d = min(v[id].d, ++t);
  for(int i=0;i<v[id].c.size();i++) {
    rec(v[id].c[i], t);
  }
  v[id].f = max(v[id].f, ++t);
}


bool asc(const Node &right, const Node &left){return right.id < left.id;}

int main(){
  cin >> n;
  
  v[0].id = 0;  
  for(int i=1;i<=n;i++){
    int t, a;  cin >> a >> t;
    vector<int> b(t);
    for(int j=0;j<t;j++){
      int val;cin >> val;
      b[j] = val;
    }
    v[a].id = a;
    v[a].c = b;
  }
  sort(v.begin(), v.end(), asc);

  int ti = 0;
  for(int i=1;i<=n;i++){
    rec(i, ti);
  }

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

C++: #include <stdio.h>

int numberd=1, numberf=1;
int map[100][100];
int numofroot[100];
int visited[100];
int d[100];
int f[100];
int map_size;
 
void get_map();
void print_map();
int search(int node);
void print_result();
int main()
{
  get_map();
  //print_map();
  for(int i=0;i<map_size;i++)
    {
      if(d[i]==0)
	{
	  search(i);
	}
    } 
  print_result();
  return 0;
}

int search(int node)
{
  int k;
  if(d[node]==0)//not visited
    {
      d[node]=numberd;//visited
      numberd++;
      if(numofroot[node]!=0)
	{
	  for(int i=0;i<numofroot[node];i++)
	    {
		{
		  k=search(map[node][i]-1);
		  if(k==-1)
		    {
		      //f[node]=numberd;
		      //numberd++;
		      //return -1;
		    }
		}
	    }
	}
      //else
	{
	  f[node]=numberd;
	  numberd++;
	  return -1;
	}
    }
  else//visited
    {
      return 1;
    }

  return -1;
}

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

void get_map()
{
  int k;
   scanf("%d", &map_size);
  for(int i=0;i<map_size;i++)
    {
      scanf("%d", &k);
      scanf("%d", &numofroot[i]);
      for(int j=0;j<numofroot[i];j++)
	{
	  scanf("%d", &map[i][j]);
	}
    }
  return ;
}

void print_map()
{
  for(int i=0;i<map_size;i++)
   {
     printf("%d", numofroot[i]);
     for(int j=0;j<numofroot[i];j++)
       {
	 printf("%d", map[i][j]);
       }
     if(i!=map_size-1)
       {
     puts("");
       }
   }
  puts("");
  return ;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

vector<vector<ll>> G;
vector<ll> d, f;
vector<bool> b;
ll t;

ll dfs(ll v, ll t) {
    b[v] = true;
    d[v] = t;
    for (auto nv : G[v]) {
        if (b[nv]) continue;
        t = dfs(nv, t + 1);
    }
    f[v] = t + 1;
    return t + 1;
}

int main() {
    ll n;
    cin >> n;
    G.resize(n), d.resize(n), f.resize(n), b.resize(n);
    rep(i, n) {
        ll u, k;
        cin >> u >> k;
        u--;
        rep(j, k) {
            ll v;
            cin >> v;
            v--;
            G[u].emplace_back(v);
        }
    }
    ll now = 0;
    rep(i, n) {
        if(b[i]) continue;
        now = dfs(i, now + 1);
    }
    rep(i, n) cout << i+1 << " " << d[i] << " " << f[i] << endl;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;++i)

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int hlt = 0;
vector<P> times;
vector<vector<int>> node;
vector<bool> searched;

void solve(int index){
    if(!searched[index])searched[index]=true;else return;
    times[index].first=++hlt;
    REP(i,(int)node[index].size())
        solve(node[index][i]-1);
    times[index].second=++hlt;
}

int main(){
    int n; cin>>n;
   node.resize(n);
   times.resize(n,P(0,0));
   searched.resize(n,false);
   REP(i,n){
    int index,size; cin >> index >> size; index--;
    if(size==0)continue;
    node[index].resize(size);
        REP(j,size)cin >> node[index][j];
    sort(node[index].begin(),node[index].end());
   }
   REP(i,n)
    if(!searched[i])
        solve(i);
   REP(i,n)
    cout<<i+1<<" "<<times[i].first<<" "<<times[i].second<<endl;
}

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

using namespace std;

typedef struct{
  int begin;
  int end;
  bool f;
}fint;
fint T[101];

int times = 1;
int n;
int graph[101][101];

void bfs(int now){

  T[now].f = true;
  T[now].begin = times++;

  for( int i = 1 ; i <= n; i++ ){
    if( graph[now][i] == 1 && !T[i].f ) bfs(i);
  }
  T[now].end = times++;

}

int main(void){

  int s,t,u;
  cin >> n;
  for( int i = 0 ; i < n ; i++ ){
    cin >> s >> t;
    for( int j = 1 ; j <= t ; j++ ){
      cin >> u;
      graph[s][u] = 1;
    }
  }
  for( int i = 1 ; i <= n ; i++ ){
    T[i].begin = 0;
    T[i].end = 0;
    T[i].f = false;
  }
  for( int i = 1 ; i <= n ; i++ ){
    if( !T[i].f ) bfs(i);
  }

  for( int i = 1 ; i <= n ; i++ ){
    cout << i << " " << T[i].begin << " " << T[i].end << endl;
  }


  return 0;
}

C++: #include <iostream>

using namespace std;

	int TIME = 0;
	int d[101];
	int f[101];
	int num;
	int graph[101][101] = {0};

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

	for(int i=1;i<=num;i++){
		if(graph[x][i] == 1 && d[i]==0){
			dfs(i);
		}
	}
	f[x] = ++TIME;
}

int main(){
	int hon;
	int eda;
	int ver;

	cin>>num;
	for(int i=0;i<num;i++){
		cin>>eda;
		cin>>hon;
		for(int j=0;j<hon;j++){
			cin>>ver;
			graph[eda][ver]++;
		}
	}
	
	for(int i=1;i<=num;i++){
		if(d[i]==0)
			dfs(i);
	}

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

	return 0;
}