Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

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

C++: #if 0

#endif

#include <iostream>
#include <vector>
using namespace std;

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int G[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(G[cur][dst]==1&&c[dst]==0){
			dfs(dst);
		}
	} 
	t += 1;
	mytime2[cur]=t;
}


int main()
{
	vector<int> v[110];
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int tmp;
			cin>>tmp;
			v[u].push_back(tmp);
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			G[i][j]=0;
		}
	}
	for(int i=1;i<n+1;i++){
		for(int j=0;j<v[i].size();j++){
			G[i-1][v[i][j]-1]=1; 
		}
	}
	for(int i=0;i<n;++i){
		dfs(i);
		cout<<(i+1)<<' '<<mytime1[i+1]<<" "<<mytime2[i+1] <<endl;
}
}

C++: 
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int n;
int graph[100][100];
int d[100];
int f[100];
int now=0;
int k[100];
bool beg[106];
void dfs(int p)
{
    
   beg[p-1]=true;
 //  cout<<“p”<< p<<endl;
   //if(d[p-1]==-1)
   d[p-1]=now;
  // cout<<“now “<<now<<endl;
   if(k[p-1]==0)
   {
       now++;
       f[p-1]=now;
   }
   else
   {
       for(int i=0;i<k[p-1];i++)
       {
           if(beg[graph[p-1][i]-1]==false)
           {
               now++;
               dfs(graph[p-1][i]);
           }
       }
       now++;
       f[p-1]=now;
   }
}
int main(){
   cin>>n;
   for(int i=0;i<n;i++)
   {
       beg[i]=false;
       d[i]=-1;
       f[i]=-1;
       int number;
       cin>>number;
       cin>>k[i];
       for(int j=0;j<k[i];j++)
           cin>>graph[i][j];
   }
   now=0;
   for(int i=0;i<n;i++)
   {
       if(beg[i]==false)
       {
           now++;
           dfs(i+1);
       }
   }
   for(int i=0;i<n;i++)
   {
       cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
   }
   return 0;
}

C++: #include <bits/stdc++.h>

int d[128];
int f[128];
bool c[128][128];
int n;
int t;
int checked[128];

void dfs(int i) {
  if( checked[i] ) return;
  checked[i] = true;
  t += 1;
  d[i] = t;
  for(int k = 1; k <= n; ++k) {
    if( c[i][k] ) {
      dfs(k);
    }
  }
  t += 1;
  f[i] = t;
  return;
}

int main(void) {

  for(int i = 0; i < 128; ++i) {
    for(int j = 0; j < 128; ++j) {
      c[i][j] = false;
    }
  }

  std::cin >> n;

  int u, k, v;
  for(int i = 0; i < n; ++i) {
    std::cin >> u >> k;
    for(int j = 0; j < k; ++j) {
      std::cin >> v;
      c[u][v] = true;
    }
  }

  for(int i = 1; i <= n; ++i) {
    dfs(i);
  }

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