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

/*****************************************/
/*            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);

  dfs(list,1,d,f,&t);

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



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


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) 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] = 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 <bits/stdc++.h>


using namespace std;

int n;
vector< vector<int> > edges(100);
int t;
vector< pair<int,int> > ans(100);
vector< bool > vis(100, false);

void dfs(int v){
  t++;
  vis[v] = true;
  ans[v].first = t;
  for(int i : edges[v])
    if(vis[i] == false)
      dfs(i);
  t++;
  ans[v].second = t;
}

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

  for(int i = 0; i < n; i++){
    int k;
    cin >> k >> k;
    for(int j = 0; j < k; j++){
      int to;
      cin >> to;
      edges[i].push_back(to-1);
    }
  }

  t = 0;
  dfs(0);
  for(int i = 0; i < n; i++){
    cout << i + 1 << ' ' <<  ans[i].first << ' ' << ans[i].second << endl;
  }
}

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

void dfs(int cur);
int df[100][2]={};
bool dc[100]={};
bool adj[100][100]={};//初期化を忘れない
int n,u,v,k;
int t = 1;

int main(){
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> u >> k;
    for (int j=0; j<k; j++){
      cin >> v;
      adj[u-1][v-1] = true;
    }
  }
  
 
  dfs(0);
  
  for (int i=0; i<n; i++)
    cout << i+1 << " " << df[i][0] << " " << df[i][1] << endl;

}

void dfs(int cur){
  dc[cur] = true;
  df[cur][0] = t;
  t += 1;
  bool a = false;
  for (int i=0; i<n; i++){
    if (adj[cur][i] && !dc[i]){
      dfs(i);
      a = true;
    }
  }
  if (!a) t -= 1;
  t += 1;
  df[cur][1] = t;  
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#define white 0
#define grey 1
#define black -1
using namespace std;

int a[110][110],n;
int color[110];
int t;
int ts[110],te[110];
int nt[110];

void dfsinit()
{
    for(int i=1;i<=n;i++)
        {
            color[i]=white;
            nt[i]=1;
        }
}

int next(int i)
{
    for(int j=nt[i];j<=n;j++)
    {
        nt[i]=j+1;
        if(a[i][j]) return j;
    }
    return -1;
}

void dfsvisit(int u)
{
    for(int i=1;i<=n;i++)
        nt[i]=1;
    stack<int>s;
    s.push(u);
    ts[u]=++t;
    color[u]=grey;
    while(!s.empty())
    {
       int r=s.top();
       int v=next(r);
       if(v!=-1)
       {
          if(color[v]==white)
          {
              color[v]=grey;
              ts[v]=++t;
              s.push(v);
          }
       }
       else
       {
           color[r]=black;
           te[r]=++t;
           s.pop();
       }
    }
}

void dfs()
{
    dfsinit();

    for(int i=1;i<=n;i++)
    {
        if(color[i]==white)
        {
            dfsvisit(i);
        }
    }
}

int main()
{
   int key,d,x;
   t=0;
   memset(a,0,sizeof(a));
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
       scanf("%d%d",&key,&d);
       for(int j=1;j<=d;j++)
       {
        scanf("%d",&x);
        a[key][x]=1;
       }
   }

   dfs();
   for(int i=1;i<=n;i++)
   {
       printf("%d %d %d\n",i,ts[i],te[i]);
   }
   return 0;
}

C++: #include <iostream>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;

int color[MAX];
bool M[MAX][MAX];
int n;
int tt;
int d[MAX];
int f[MAX];

void dfs(int u) {
	color[u] = GRAY;
	d[u] = ++tt;
	for (int v = 0; v < n; v++) {
		if (M[u][v] && color[v] == WHITE) {
			dfs(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs_init() {
	for (int i = 0; i < n; i++) {
		color[i] = WHITE;
	}
	tt = 0;
	for (int u = 0; u < n; u++) {
		if (color[u] == WHITE) {
			dfs(u);
		}
	}
	for (int u = 0; u < n; u++) {
		cout << u + 1 << " ";
		cout << d[u] << " " << f[u] << endl;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = false;
		}
		d[i] = f[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		int u, k, v;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			M[u - 1][v - 1] = true;
		}
	}
	
	dfs_init();

	return 0;
}