Go: package main

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

func main() {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	nextInt := func() int { scn.Scan(); r, _ := strconv.Atoi(scn.Text()); return r }
	w := bufio.NewWriter(os.Stdout)

	n := nextInt()
	vecs := make([][]int, n)
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			vecs[u-1] = append(vecs[u-1], nextInt()-1)
		}
	}

	ds := make([]int, n)
	fs := make([]int, n)
	founds := make([]bool, n)
	t := 0
	for i := range founds {
		if !founds[i] {
			t = dfs(vecs, ds, fs, founds, i, t)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(w, i+1, ds[i], fs[i])
	}

	w.Flush()
}

func dfs(vecs [][]int, ds, fs []int, founds []bool, i, t int) (time int) {
	t++
	ds[i] = t
	founds[i] = true
	for _, v := range vecs[i] {
		if !founds[v] {
			t = dfs(vecs, ds, fs, founds, v, t)
		}
	}
	t++
	fs[i] = t

	return t
}

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;
}

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 u = 0; u < n; u++) {
        if (color[u] == WHITE) dfs_visit(u);
    }
    for (int i = 0; i < n; i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main(int argc, char const *argv[])
{
    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;
}