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++: #define _CRT_SECURE_NO_WARNINGS
#include<cstdio>

bool table[102][102] = {};
int color[102] = {}; //0:?????¢?´¢???1:?¨??????????, 2:??¢?´¢??????
int n, counter = 0;
int t_visit[102] = {};
int t_finish[102] = {};

void DFS(int y) {
	
	for (int j = 0; j <= n - 1;j++) {

		//?¨????or??¢?´¢???????????£???????????????
		if ((table[y][j] == 1)&&(color[j] == 0)) {
			color[y] = 1; //?¨???????????????????
			if (t_visit[y] == 0) t_visit[y] = ++counter;
			DFS(j);
		}

	}

	color[y] = 2; //??¢?´¢???????????????
	if (t_visit[y] == 0) t_visit[y] = ++counter;
	if (t_finish[y] == 0) t_finish[y] = ++counter;
	
}

int main(void) {
	int u, k, s;

	scanf("%d", &n);

	for (int i = 0;i <= n - 1;i++) {
		scanf("%d %d", &u, &k);
		for (int j = 0;j <= k - 1;j++) {
			scanf("%d", &s);
			table[u - 1][s - 1] = 1;
		}
	}


	for (int i = 0;i <= n - 1;i++) {
		if (color[i] == 0) {
			DFS(0);
		}
	}


	for (int i = 0; i <= n - 1;i++) {
		printf("%d %d %d\n", i + 1, t_visit[i], t_finish[i]);
	}

	return 0;
}

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

vector<int> graph[100];
int d[100], f[100];
int visited = 0;

void dfs(int id){
    d[id] = visited + 1;
    for(int i = 0; i < graph[id].size(); i++)
	{
        if(graph[id][i] != id && !d[graph[id][i]] && !f[graph[id][i]])
		{
			dfs(graph[id][i]);
		}
    }
    f[id] = visited + 1;
}

int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++)
	{
        int u, k;
        cin >> u >> k;
        for(int j = 0;j < k;j++)
		{
            int v;
            cin >> v;
            graph[u - 1].push_back(v - 1);
        }
    }
    dfs(0);
    for(int i = 0;i < n;i++)
	{
        if(!f[i]) 
		{
			dfs(i);
		}
    }
    for(int i = 0;i < n;i++)
	{
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

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

int n;
vector<vector<int> > A;
vector<vector<int> > T;
int t = 0;

void dfs(int cur){ // cur????¨????
    // cur ????¨??????????????¨????
    t += 1;
    T[cur][0] = t;
    // ???????¢??????¨??¨???
    // cerr << "visiting " << cur << " " << t << endl;

    for(int dst = 0; dst < n; ++dst){ // ??¨???????????? dst ????????????
        if(A[cur][dst] == 1 && T[dst][0] == -1){ // cur??????dst??????????????????,dst???????¨??????????
            dfs(dst);
        }
    }
    // cur ????¨????????????????????¨????
    t += 1;
    T[cur][1] = t;
    // ??¢??°?????????????????????????????? (?????¢??°)
    return; // ?????\???
}

int main(){
    cin >> n;
    A = vector<vector<int> >(n, vector<int>(n, 0));
    T = vector<vector<int> >(n, vector<int>(2, -1));
    for(int i=0; i<n; ++i){
        int k;
        cin >> k;
        // 1~n???index?????¨????????????????????????????????????1????????????0~n-1????????????
        k -= 1;
        int u;
        cin >> u;
        for(int j=0; j<u; ++j){
            int v;
            cin >> v;
            v -= 1;
            A[k][v] = 1;
        }
    }
    for(int i=0; i<n; ++i){
        if(T[i][0] == -1){
          dfs(i);
        }
    }
    for(int i=0; i<n; ++i){
        cout << i+1 << " " << T[i][0] << " " << T[i][1] << endl;
    }
}

C++: #include <cstdio>

typedef struct{
	bool isVisited;
	int degree;
	int start;
	int end;
	int *neighbors;
} node;

int count = 1;

void dfs(node* nodes, int id){
	nodes[id].isVisited = true;
	if (nodes[id].start == 0) nodes[id].start=count;
	for (int i=0; i<nodes[id].degree; i++){
		if (!nodes[nodes[id].neighbors[i]].isVisited){
			count ++;
			dfs(nodes, nodes[id].neighbors[i]);
		}
	}
	count++;
	nodes[id].end = count;
}

int main(){
	int n, d, r, id;
	node *nodes;

	scanf("%d", &n);
	nodes = new node[n];
	for (int i=0; i<n;i++){
		nodes[i].isVisited=false;
		scanf("%d %d", &r, &d);
		nodes[i].degree=d;
		nodes[i].neighbors = new int[d];
		nodes[i].start = 0;
		
		for (int j=0;j<d;j++){
			scanf("%d", &id);
			nodes[i].neighbors[j] = id-1;
		}
	}

	dfs(nodes, 0);
	for (int i=0; i<n;i++){
		printf("%d %d %d\n", i, nodes[i].start, nodes[i].end);
		delete []nodes[i].neighbors;
	}
	delete []nodes;
	return 0;
}

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