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 <map>
using namespace std;

map<int, vector<int>> A;
int color[101];
int start[101];
int endTime[101];
int elapsed = 0;

void dfs(int u) {
    elapsed++;
    color[u] = 1;
    start[u] = elapsed;
    for (vector<int>::iterator it = A[u].begin(); it != A[u].end(); it++) {
        if (color[*it] == 0) {
            dfs(*it);
        }
    }
    endTime[u] = ++elapsed;
}

int main() {
    int n;
    cin >> n;

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

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

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

C++: #include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

struct Timestamp{
	int discovered;
	int finished;
};

int main(){
	int n;
	cin >> n;

	set<int> A[n+1];
	bool reached[n+1]{};
	int v1, v2, deg;
	r(i, n){
		cin >> v1 >> deg;

		r(j, deg){
			cin >> v2;
			A[v1].insert(v2);
			//A[v2].insert(v1);
		}
	}

	Timestamp ts[n+1];
	for(int i = 1; i <= n; i++){
		ts[i].discovered = 0;
		ts[i].finished = 0;
	}
	ts[1].discovered = 1;


	int time = 0;
	stack<int> s;

	while(true){
		for (int i = 1; i <= n; i++) {
			if (reached[i])
				continue;
			reached[i] = true;
			s.push(i);
			time++;
			ts[i].discovered = time;
			goto DFS;
		}
		break;

		DFS:;
		while (!s.empty()) {
			v1 = s.top();

			bool hasNext = false;
			for (int v2 : A[v1]) {
				if (!reached[v2]) {
					reached[v2] = true;
					s.push(v2);
					hasNext = true;
					break;
				}
			}

			if (!ts[v1].discovered) {
				time++;
				ts[v1].discovered = time;
			}

			if (!hasNext) {
				time++;
				ts[v1].finished = time;
				s.pop();
			}
		}
	}

	for(int i = 1; i <= n; i++){
		printf("%d %d %d\n", i, ts[i].discovered, ts[i].finished);
	}

	return 0;
}

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

std::vector<pair<int, int> > stamp(101);
std::vector<std::vector<int> > v(101);
bool isCheckd[101];
int cnt = 0;

void dfs(int k){
	cnt++;
	isCheckd[k] = true;
	stamp[k].first = cnt;
	for(int i=0;i<v[k].size();i++){
		int next = v[k][i];
		if(!isCheckd[next]){
			dfs(next);
		}
	}
	cnt++;
	stamp[k].second = cnt;
}

int main(){
	int n;

	fill(isCheckd,isCheckd+101,false);
	isCheckd[0] = true;
	cin >> n;

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

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


	for(int i=0;i<n;i++){
		cout << i+1 <<" "<< stamp[i+1].first <<" " <<stamp[i+1].second<< endl;
	}

	return 0;
}

C++: #include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
	int v;
	color[u]=GRAY;
	d[u]=++tt;
	for(v=0;v<n;v++){
		if(M[u][v]==0) continue;
		if(color[v]==WHITE){
			dfs_visit(v);
		}
	}
	color[u]=BLACK;
	f[u]=++tt;
}

void dfs(){
	int u;
	
	for(u=0;u<n;u++) color[u] = WHITE;
	tt=0;
	
	for(u=0;u<n;u++){
		if(color[u]==WHITE)dfs_visit(u);
	}
	
	for(u=0;u<n;u++){
		printf("%d %d %d\n",u+1,d[u],f[u]);
	}
}

int main() {
	int u,v,k,i,j;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			M[i][j]=0;
		}
	}
	
	for(i=0;i<n;i++){
		scanf("%d%d",&u,&k);
		u--;
		for(j=0;j<k;j++){
			scanf("%d",&v);
			v--;
			M[u][v]=1;
		}
	}
	
	dfs();
	
	return 0;
}

C++: //
//  main.cpp
//  depth_first_search
//
//  Created by ???????????? on 2017/10/22.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>

#define n_max 100

using namespace std;

int n, t = 0;
int M[n_max][n_max], color[n_max], d[n_max], f[n_max];

void encode_graph(int n){
    int i, j, id, num, node;
    
    //initialize with 0
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            M[i][j] = 0;
        }
    }
    
    for (i = 0; i < n; i++){
        scanf("%d", &id);
        scanf("%d", &num);
        for(j = 0; j < num; j++){
            scanf("%d", &node);
            M[id-1][node-1] = 1;
        }
    }
}

void dfs(int u){
    color[u] = 1;
    d[u] = ++t;
    for (int v = 0; v < n; v++){
        if((M[u][v]) && (color[v] == 0)){
            dfs(v);
        }
    }
    color[u] = 2;
    f[u] = ++t;
}

void dfs_init(int n){
    for(int i = 0; i < n ; i++){
        color[i] = 0;
    }
    dfs(0);
}


int main(int argc, const char * argv[]) {
    scanf("%d", &n);
    
    encode_graph(n);
    
    dfs_init(n);
    
    for(int i = 0; i < n; i++){
        cout<<i+1<<" "<<d[i]<<" "<< f[i]<<endl;
    }
    
//    std::cout << "Hello, World!\n";
    return 0;
}