Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type nodeKey int

type DirectedGraphNode struct {
	key       nodeKey
	adjacents []*DirectedGraphNode
	visited   bool
	d         int
	f         int
	parent    *DirectedGraphNode
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(l, r nodeKey) {
	g.nodes[l].adjacents = append(g.nodes[l].adjacents, g.nodes[r])
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for iNodes := 0; iNodes < nNodes; iNodes++ {
		graph.nodes[iNodes] = &DirectedGraphNode{}
		graph.nodes[iNodes].key = nodeKey(iNodes)

		graph.nodes[iNodes].visited = false
		graph.nodes[iNodes].d = infty
		graph.nodes[iNodes].f = infty
		graph.nodes[iNodes].parent = nil
	}
	return &graph
}

type QueueEntry struct {
	node *DirectedGraphNode
	next *QueueEntry
}

type Queue struct {
	head, tail *QueueEntry
}

func (q *Queue) enqueue(node *DirectedGraphNode) {
	entry := QueueEntry{}
	entry.node = node

	if q.tail == nil {
		q.head = &entry
		q.tail = &entry
		return
	}

	q.tail.next = &entry
	q.tail = q.tail.next
}

func (q *Queue) dequeue() *QueueEntry {
	if q.head == nil {
		return nil
	}
	poped := q.head
	q.head = q.head.next
	if q.head == nil {
		q.tail = nil
	}
	return poped
}

func (q *Queue) isEmpty() bool {
	return q.head == nil
}

var time = 0

func fillDistancesByDepthFirstSearch(g *DirectedGraph) {
	for _, u := range g.nodes[1:] {
		if !u.visited {
			dfsVisit(g, u)
		}
	}
}

func dfsVisit(g *DirectedGraph, u *DirectedGraphNode) {
	time++
	u.d = time

	u.visited = true
	for _, v := range u.adjacents {
		if !v.visited {
			v.parent = u
			dfsVisit(g, v)
		}
	}
	time++
	u.f = time
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	g := newDirectedGraph(nNodes + 1)

	for iNode := 0; iNode < nNodes; iNode++ {
		nodeKeyLeft := nodeKey(nextInt())
		nAdj := nextInt()
		for iAdj := 0; iAdj < nAdj; iAdj++ {
			nodeKeyRight := nodeKey(nextInt())
			g.setAdjacency(nodeKeyLeft, nodeKeyRight)
		}
	}

	fillDistancesByDepthFirstSearch(g)

	for iNode := 1; iNode <= nNodes; iNode++ {
		node := g.nodes[iNode]
		fmt.Println(node.key, node.d, node.f)
	}
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <cstdlib>

const int MAX_N = 100;

struct Node {
  int v;
  int firstVisitedTime;
  int lastVisitedTime;
  bool visited;
};

void visit(int *count, int n, std::vector<std::list<int> *> *graph, std::vector<struct Node *> *nodes) {
  (*count)++;
  
  struct Node *node = nodes->at(n);

  if (!node->visited) {
    node->firstVisitedTime = *count;
    node->visited = true;
  }  

  //  std::cout << (*count) << " = " << n << std::endl;

  std::list<int> *neighbors = graph->at(n);

  while (!neighbors->empty()) {
    int v = neighbors->front();
    neighbors->pop_front();
    
    if (!nodes->at(v)->visited) {
      visit(count, v, graph, nodes);
    }
  }

  (*count)++;
  node->lastVisitedTime = (*count);

  //  std::cout << (*count) << " = " << n << std::endl;
}

int main(void) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);  

  int n = 0;
  std::cin >> n;

  std::vector<std::list<int> *> *graph = new std::vector<std::list<int> *>(n + 1);
  std::vector<struct Node *> *nodes = new std::vector<struct Node *>(n + 1);
  
  for (int i = 1; i <= n; i++) {
    int v = 0;
    std::cin >> v;

    int k = 0;
    std::cin >> k;

    std::list<int> *neighbors = new std::list<int>();

    for (int i = 0; i < k; i++) {
      int a = 0;
      std::cin >> a;

      neighbors->push_back(a);
    }

    graph->at(i) = neighbors;

    struct Node *node = (struct Node *) std::malloc(sizeof(struct Node));

    node->v = i;
    node->firstVisitedTime = 0;
    node->lastVisitedTime = 0;
    node->visited = false;
    
    nodes->at(i) = node;
  }

  int count = 0;

  for (std::vector<struct Node *>::iterator iterator = nodes->begin() + 1; iterator != nodes->end(); ++iterator) {
    struct Node *node = *iterator;
    
    if (!node->visited) {
      visit(&count, node->v, graph, nodes);
    }
  }

  for (std::vector<struct Node *>::iterator iterator = nodes->begin() + 1; iterator != nodes->end(); ++iterator) {
    struct Node *node = *iterator;
        
    std::cout << node->v << " " << node->firstVisitedTime << " " << node->lastVisitedTime << std::endl;
  }
  
  return 0;
}

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

void dfs_init();
void dfs(int u);

int n,**List,*deg,*d,*f;
bool **M;
string *color;
stack<int> S;
int vertex,time;

int main(){
	cin>>n;
	List = new int*[n]; M = new bool*[n]; deg = new int[n]; color = new string[n]; d = new int[n]; f = new int[n];
	for(int i=0;i<n;i++) List[i] = new int[n]; for(int i=0;i<n;i++) M[i] = new bool[n];
	for(int i=0;i<n;i++){
		List[i] = List[i]-1;
		M[i] = M[i]-1;
	}
	List = List-1; M = M-1; deg = deg-1; color = color-1; d = d-1; f = f-1;

	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			M[i][j] = false;
		deg[i] = 0; d[i] = 0; f[i] = 0;
	}
	
	int k;
	for(int i=1;i<=n;i++){
		cin>>vertex>>k;
		for(int j=1;j<=k;j++){
			cin>>List[vertex][j];
			M[vertex][List[vertex][j]] = true;
		}
	}

	dfs_init();

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

	for(int i=1;i<=n;i++){
		delete [] (List[i]+1); delete [] (M[i]+1);
	}
	delete [] (List+1); delete [] (M+1);
	delete [] (deg+1); delete [] (color+1); delete [] (d+1); delete [] (f+1);
	cin.get(); cin.get();
}

void dfs_init(){
	for(int i=1;i<=n;i++) color[i] = "WHITE";
	for(int i=1;i<=n;i++){
		if(color[i]=="WHITE"){
			dfs(i);
		}
	}
}

void dfs(int u){
	color[u] = "GRAY";
	d[u] = ++time;
	for(int v=1;v<=n;v++){
		if(M[u][v]==false) continue;
		if(color[v]=="WHITE"){
			dfs(v);
		}
	}
	color[u] = "BLACK";
	f[u] = ++time;
}