Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

class DirectedGraph
{
public:
    DirectedGraph()
    : t(1)
    {}
    DirectedGraph(int n)
    : t(1), g(vector< vs32 >(n)), d(vs32(n, 0)), f(vs32(n, 0))
    {}
    ~DirectedGraph() {}

    void dfs(int i)
    {
        d[i] = t++;
        rep (j, g[i].size())
        {
            if (d[g[i][j]] == 0)
            {
                dfs(g[i][j]);
            }
        }
        f[i] = t++;
    }

    int t;
    vector< vs32 > g;
    vs32 d;
    vs32 f;
};

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

    int n;
    cin >> n;

    DirectedGraph dg(n);
    int u, v;
    int c;
    rep (i, n)
    {
        cin >> u >> c;
        --u;
        dg.g[u].resize(c);
        rep (j, c)
        {
            cin >> v;
            --v;
            dg.g[u][j] = v;
        }
    }

    rep (i, n)
    {
        if (dg.d[i] == 0)
        {
            dg.dfs(i);
        }
    }

    rep (i, n)
    {
        cout << i + 1 << " " << dg.d[i] << " " << dg.f[i] << "\n";
    }
    return 0;
}

C++: 
#include<iostream>

using namespace std;

const int MAX = 100;

void search(bool graph[MAX][MAX], int find[], int done[], int n, int u,int& count) {
	count++;
	find[u] = count;
	for (int i = 0; i < n; i++) {
		if (graph[u][i] && find[i] == 0) {
			search(graph, find, done, n, i, count);
		}
	}
	count++;
	done[u] = count;
}

int main() {
	bool check[MAX] = { false };
	int find[MAX] = { 0 };
	int done[MAX] = { 0 };
	bool graph[MAX][MAX] = { {false} };
	int N;

	cin >> N;
	for (int i = 0; i < N; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int temp;
			cin >> temp;
			graph[u - 1][temp - 1] = true;
		}
	}

	int count = 0;
	for (int i = 0; i < N; i++) {
		if (find[i] == 0) {
			search(graph, find, done, N, i, count);
		}
	}

	for (int i = 0; i < N; i++) {
		cout << i + 1 << " " << find[i] << " " << done[i] << endl;
	}

	return 0;
}