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<stack>
#include<climits>

using namespace std;

class Node{
private:
 unsigned long nodeId;
 unsigned long timestampStart;
 unsigned long timestampFinish;
 vector<unsigned long> adjectNode;
 unsigned long checkedNodeNum;

 void stampStart(unsigned long time){
  timestampStart = time;
 };

 void stampFinish(unsigned long time){
  timestampFinish = time;
 };
 

public:
 Node(unsigned long nodeId = 0, unsigned long adjectNodenum = 0)
                  : nodeId(nodeId),
                    timestampStart(0),
                    timestampFinish(0),
                    adjectNode(vector<unsigned long>(adjectNodenum, 0)),
                    checkedNodeNum(0){

 for(unsigned long adjectNode_i = 0; adjectNode_i < adjectNodenum; ++adjectNode_i){
  unsigned long adjectNodeId = 0; cin >> adjectNodeId;

  adjectNode[adjectNode_i] = adjectNodeId;
 } 

 };

 unsigned long getNotCheckedAdjectNode(unsigned long time){
  unsigned long AdjectNodeMax = adjectNode.size();
  if(checkedNodeNum == 0){
   stampStart(time);
  }else if(checkedNodeNum >= AdjectNodeMax){
   stampFinish(time);
   return ULONG_MAX;
  }


  ++checkedNodeNum;

  if(AdjectNodeMax == 0){
   return nodeId-1;
  }

  return adjectNode[checkedNodeNum-1]-1;

 };

 void display(){
  cout << nodeId          << " ";
  cout << timestampStart  << " ";
  cout << timestampFinish << endl;
 };


protected:
};

class Graph{
private:
 vector<Node*> graph;

public:
 Graph(unsigned long nodeNum = 0)
                  : graph(vector<Node*>(nodeNum, 0)){
  for(unsigned long node_i = 0; node_i < nodeNum; ++node_i){
   unsigned long nodeId = 0; cin >> nodeId;
   unsigned long adjectNodenum = 0; cin >> adjectNodenum;
   Node* temp_node = new Node(nodeId, adjectNodenum);
   graph[nodeId-1] = temp_node;
  }
 };

 void DepthFirstSearch(){
  unsigned long time = 1;
  stack<unsigned long> checkedNode;
  if(graph[0] == 0) return ;

  checkedNode.push(0);
  while(!checkedNode.empty()){
   unsigned long nowNode = checkedNode.top();
   if(unsigned long nextNode = graph[nowNode]->getNotCheckedAdjectNode(time)){
    if(nextNode == ULONG_MAX){
     checkedNode.pop();
    }else if(nextNode == nowNode){
    }else{
     checkedNode.push(nextNode);
    }
   }
   ++time;
  }

 };

 void display(){
  for(unsigned long node_i = 0, nodeNum = graph.size(); node_i < nodeNum; ++node_i){
   graph[node_i]->display();
  }
 };

protected:

};

int main(){
 unsigned long nodeNum = 0; cin >> nodeNum;

 Graph graph(nodeNum);
 graph.DepthFirstSearch();
 graph.display();

 return 0;
};

C++: #include<iostream>
#include<stack>
using namespace std;
#define MAX 100
#define NIL -1

int n, T[MAX+1][MAX+1];
int laps = 0, d[MAX+1], f[MAX+1];

void solve(int i){
    d[i] = ++laps;
    for ( int j = 1; j <= n; j++){
      if ( T[i][j] && d[j] == NIL ){
        solve(j);
      }
    }

    f[i] = ++laps;
}

int main(){
  cin >> n;
  for ( int i = 1; i <= n; i++){
    d[i] = f[i] = NIL;
    for ( int j = 1; j <= n; j++){
      T[i][j] = 0;
    }
  }

  int u, k, v;
  for ( int i = 1; i <= n; i++){
    cin >> u >> k;
    for ( int j = 0; j < k; j++){
      cin >> v;
      T[u][v] = 1;
    }
  }

  for ( int i = 1; i <= n; i++){
    if ( d[i] == NIL){
      solve(i);
    }
  }

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

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void dfs(int v, int &t, const V<V<int>> &g, V<P> &time) {

    t++;
    time[v].fi = t;
    for(int nv : g[v]) {
        if(time[nv].fi) continue;
        dfs(nv, t, g, time);
    }
    t++;
    time[v].se = t;
}

int main(){

    int n;
    cin >> n;
    V<V<int>> g(n);
    rep(i,n) {
        int a, k;
        cin >> a >> k;
        a--;
        rep(j,k) {
            int b;
            cin >> b;
            b--;
            g[a].push_back(b);
        }
    }
    V<P> time(n);
    int t = 0;
    rep(i,n) {
        if(time[i].fi) continue;
        dfs(i, t, g, time);
    }
    rep(i,n) {
        printf("%d %d %d\n", i+1, time[i].fi, time[i].se);
    }
}