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<string>
#include<stack>
#include<unordered_set>
#include<algorithm>

#define N 1000

int n, u, k, v;
int G[N][N];
std::stack<int> S;
std::unordered_set<int> hasVisited;
int count, d[N], f[N];

void visit(int x) {
    hasVisited.insert(x);
    d[x] = count++;
    for(int i = 1; i <= n; i++) {
        if(G[x][i] != 0 && hasVisited.find(i) == hasVisited.end()) {
            visit(i);
        }
    }
    f[x] = count++;
}

int main() {

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            G[i][j] = 0;
        }
    }
    std::cin >> n;
    for(int i = 0; i < n; i++) {
        std::cin >> u >> k;
        for(int j = 0; j < k; j++) {
            std::cin >> v;
            G[u][v] = 1;
        }
    }

    count = 1;
    for(int i = 0 ; i < N; i++) {
        d[i] = 0;
        f[i] = 0;
    }

    for(int i = 1; i <= n; i++) {
        if(hasVisited.find(i) == hasVisited.end())
            visit(i);
    }
    for(int i = 1; i <= n; i++) {
        printf("%i %i %i\n", i, d[i], f[i]);
    }

    return 0;
}

C++: //
// Created by tattsun on 2017/02/13.
//

#include <iostream>
#include <vector>

using namespace std;

#define VERTEX_MAX_NUM 101
#define NIL -1

int now = 0;
int n;
int start[VERTEX_MAX_NUM];
int finish[VERTEX_MAX_NUM];
bool visited[VERTEX_MAX_NUM];
vector<int> vertexes[VERTEX_MAX_NUM];

void _dfs(int node) {
    start[node] = ++now;
    visited[node] = true;

    auto& v = vertexes[node];

    for(auto it = v.begin(); it != v.end(); it++) {
        if(visited[*it])
            continue;
        _dfs(*it);
    }

    finish[node] = ++now;
}

void dfs() {
    for(int i=1; i<=n; i++) {
        if(visited[i]) continue;
        _dfs(i);
    }
}

int main() {
    for(int i=0; i<VERTEX_MAX_NUM; i++) {
        start[i] = NIL;
        finish[i] = NIL;
        visited[i] = false;
    }

    cin >> n;

    int u, k, p;
    for(int i=1; i<=n; i++) {
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            cin >> p;
            vertexes[i].push_back(p);
        }
    }

    dfs();

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

C++: #include <bits/stdc++.h>

int d[128];
int f[128];
bool c[128][128];
int n;
int t;
int checked[128];

void dfs(int i) {
  if( checked[i] ) return;
  checked[i] = true;
  t += 1;
  d[i] = t;
  for(int k = 1; k <= n; ++k) {
    if( c[i][k] ) {
      dfs(k);
    }
  }
  t += 1;
  f[i] = t;
  return;
}

int main(void) {

  for(int i = 0; i < 128; ++i) {
    for(int j = 0; j < 128; ++j) {
      c[i][j] = false;
    }
  }

  std::cin >> n;

  int u, k, v;
  for(int i = 0; i < n; ++i) {
    std::cin >> u >> k;
    for(int j = 0; j < k; ++j) {
      std::cin >> v;
      c[u][v] = true;
    }
  }

  dfs(1);

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

C++: #include<iostream>
#include<vector>
#include<stack>
using namespace std;
#define MAX 101
#define VISITED 0;
#define UNVISITED -1
#define NO_POSSIBLE_VERTICE -3


int d[MAX], f[MAX];
int timeStamp = 0;
vector<int> adj[MAX];
stack<int> S;

bool isAdjacentVerticeUnvisited(int currVertice, int i){
	if (f[adj[currVertice][i]] == UNVISITED) 
		return true;
	else
		return false;
}

int getNextPossibleVertice(int currVertice) {
	int i = 0;
		
	for (i = 0; i < adj[currVertice].size(); i++){
		if (isAdjacentVerticeUnvisited(currVertice, i)){
			return adj[currVertice][i];
		}
	}

	return NO_POSSIBLE_VERTICE;

}

void dfs() {

	while (!S.empty()) {
		int currVertice = S.top();

		int nextNode = getNextPossibleVertice(currVertice);

		// cout << "dfs " << currVertice << " nt:" << nextNode << "\n";

		if (nextNode == NO_POSSIBLE_VERTICE) {
			f[currVertice] = ++timeStamp;
			S.pop();
		} else {
			d[nextNode] = ++timeStamp;
			f[nextNode] = VISITED;
			S.push(nextNode);
		}
	}

}


int main() {
	int n, i, j, vertice, id, degree;
	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> id;
		cin >> degree;
		for (j = 0; j < degree; j++) {
			cin >> vertice;
			if (id != vertice){
				adj[id].push_back(vertice);
			}
		}
	}
	// init
	for (i = 1; i <= n; i++) {
		f[i] = UNVISITED;
	}

	for (i = 1; i <= n; i++) {
		if (f[i] == UNVISITED) {
			S.push(i);
			d[i] = ++timeStamp;
			f[i] = VISITED;
			dfs();
		}
	} 
	

	// for (i = 1; i <= n; i++) {
	// 	for (j = 0; j < adj[i].size(); j++)
	// 		cout << " " << adj[i][j];
	// 	cout << "\n" << i <<" size : " << adj[i].size() << "\n";
	// }

	for (i = 1; i <= n; i++) 
		cout << i << " " << d[i] << " " << f[i] <<"\n";

}