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 <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>


using namespace std;

const int N_MAX = 1000000;
/*
bool update_num_to_visit(int st, int en, int* arr){
  if(st==-1) return false;
  arr[st]--;
  return arr[st]==0;
  }*/

int main(){
  int n;
  cin >> n;
  stack<pair<int, int> > edges;
  stack<pair<int, int> > paths;
  
  int** adjl = new int*[n];
  int* d = new int[n];
  int* f = new int[n];
  
  for(int i=0; i<n; i++){
    adjl[i] = new int[n];
    memset(adjl[i], -1, n * sizeof(adjl[i][0]));
  }
  
  memset(d, -1, n*sizeof(d[0]));
  memset(f, -1, n*sizeof(f[0]));

  for(int i=0; i<n; i++){
    int row_num, k;
    cin >> row_num >> k; row_num--;
    
    for(int j=0; j<k; j++){
      int node_num;
      cin >> node_num; node_num--;
      adjl[row_num][j] = node_num; // [[3, 5, -1 , ...], [1, 3, -1, ...], [1, 2], ...]
    }
  }

  for(int row_num=n-1; row_num>=0; row_num--){
      pair<int, int> p;
      p.first = -1; p.second = row_num; // visited from nowhere
      edges.push(p);
    }

  int time = 1;
  while(!edges.empty()){
    //    cout << "time: " << time << endl;
    
    pair<int, int> edge;
    edge = edges.top(); edges.pop();
    int st, en; st = edge.first; en = edge.second;
    //    cout << "visiting: " << en << " from: " << st << endl;
    
    pair<int, int> path; 
    // record path to go back
    if(st > -1){ // exclude (-1, node)
      path.first = en; path.second = st;
      // avoid inf loop: if the node is not finished, have to go back at some point
      if(f[path.second] == -1){
	paths.push(path);
	// cout << "<" << path.first << ", " << path.second << "> pushed as a path." << endl;
      }
    }    
    
    // if first time visit, mark as visited
    if(d[en] == -1) d[en] = time;
    
    // if not first time, check if it was finished.
    // if it was already finished, continue
    if(f[en] != -1){
      continue;
    }
    
    // counter for opened nodes
    int unvisited_node_num = 0;

    // open node (reverse order)
    for(int i=n-1; i>=0; i--){
      int next_node = adjl[en][i];
      // cout << "next_node: " << next_node << endl;
      // undefined dest or visited, continue
      if(next_node == -1) continue;
      if(d[next_node] != -1){
	// if num_to_visit[en] > 0;
	continue;
      }
      // if unvisited, push into stack
      unvisited_node_num++;
      pair<int, int> next_edge; next_edge.first = en; next_edge.second = next_node;
      edges.push(next_edge);
      // cout << "<" << next_edge.first << ", " << next_edge.second << "> pushed." << endl;
    }

    // if there are no unvisited linked nodes anymore, mark the node finished
    if(unvisited_node_num == 0){
      // cout << "going back..." << endl;
      f[en] = time + 1;
      // cout << "f[" << en << "]: " << f[en] << endl;
      
      // way to go back
      if(paths.empty()) break;
      path = paths.top(); paths.pop();
      edges.push(path);
      // cout << "path pushed." << endl;
    }
    time++;
  }

  // print 'i+1, d[i], f[i]'
  
  for(int i=0; i<n; i++){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
  
  for(int i=0; i<n; i++){
    delete[] adjl[i];
  }
  delete[] adjl;
  delete[] d;
  delete[] f;
  
  return 0;
}

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

int mat[MAX][MAX] = {};
int n, time = 0, d[MAX] = {}, f[MAX] = {};
bool c[MAX];

void dfs_visit(int u){
    c[u] = true;
    d[u] = ++time;
    for(int i = 0; i < n; i++){
        if(mat[u][i] == 0)  continue;
        if(!c[i])   dfs_visit(i);
    }
    f[u] = ++time;
}

void dfs(){
    for(int i = 0; i < n; i++){
        if(!c[i])   dfs_visit(i);
    }

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

int main(){
    cin >> n;
    
    for(int i = 0; i < n; i++){
        int x, k, y;
        cin >> x >> k;
        while(k-- > 0){
            cin >> y;
            mat[x-1][y-1] = 1;
        }
    }

    dfs();
    return 0;
}

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

int n;
int a[100][100] = {0};
int k[100] = {0};
int t = 1;
int d[100] = {0};
int f[100] = {0};

int kansu( int i ){
	if ( d[i] != 0 ) return 0;
	d[i] = t;
	t++;
	for ( int j = 0; j < k[i]; j++ ) {
		if ( kansu( a[i][j] ) == 1 ) t++;
	}
	f[i] = t;
	return 1;
}

int main(){
	cin >> n;
	int s;
	for ( int i = 0; i < n; i++ ) {
		cin >> s;
		cin >> k[i];
		for ( int j = 0; j < k[i]; j++ ) {
			cin >> s;
			a[i][j] = s-1;
		}
	}
	kansu (0);
	for ( int i = 0; i < n; i++ ) {
		cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}