Go: package main

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

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

	nVerts := scanInt(sc)
	graph := make([][]int, nVerts+1)

	for i := 0; i < nVerts; i++ {
		u := scanInt(sc)
		nDegrees := scanInt(sc)

		graph[u] = make([]int, nDegrees)
		for d := 0; d < nDegrees; d++ {
			graph[u][d] = scanInt(sc)
		}
	}

	starts := make([]int, nVerts+1)
	ends := make([]int, nVerts+1)
	time := 1

	var dfs func(u int)
	dfs = func(u int) {
		if starts[u] > 0 {
			return
		}

		starts[u] = time
		time += 1

		for _, v := range graph[u] {
			dfs(v)
		}

		ends[u] = time
		time += 1
	}

	for i := 1; i <= nVerts; i++ {
		dfs(i)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= nVerts; i++ {
		fmt.Fprintf(w, "%d %d %d\n", i, starts[i], ends[i])
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

using std::cin;
using std::cout;

struct vertex {
    int vv;
    int ww;
};

//enum class VColor {White, Gray, Black};
typedef enum {White, Gray, Black} VColor;

void
dfsearch(std::vector<vertex> *gar, int gsz, int uu,
         std::vector<VColor> &color,
         std::vector<int> &dd, std::vector<int> &ff, std::vector<int> &prev,
         int &cnt)
{
    color[uu] = Gray;
    dd[uu] = ++cnt;
    //cout << uu << " " << cnt << std::endl;
    std::vector<vertex>::iterator it = gar[uu].begin();
    for (; it != gar[uu].end(); it++) {
        int     vv = (*it).vv;
        if (color[vv] == White) {
            prev[vv] = uu;
            dfsearch(gar, gsz, vv, color, dd, ff, prev, cnt);
        }
    }
    
    color[uu] = Black;
    ff[uu] = ++cnt;
    return;
}

int
main()
{
    int vn;
    std::vector<vertex> gar[100 + 1];

    cin >> vn;
    for (int idx = 0; idx < vn; idx++) {
        int uu;
        int kk;
        int vv;

        cin >> uu >> kk;
        for (int ik = 0; ik < kk; ik++) {
            cin >> vv;
            gar[uu].push_back({vv, 1});
        }
    }

#if 0
    for (int uu = 1; uu <= vn; uu++) {
        std::vector<vertex>::iterator it = gar[uu].begin();
#if 0
        for (; it != gar[uu].end(); it++) {
            printf("v = %d w = %d\n", (*it).vv, (*it).ww);
        }
#else
        for (int vv = 1; vv <= vn; vv++) {
            if (vv != 1) cout << ' ';
            if ((it != gar[uu].end()) && ((*it).vv == vv)) {
                cout << '1';
                it++;
            } else {
                cout << '0';
            }
        }
        cout << std::endl;
#endif
    }
#endif

    std::vector<VColor> color;
    std::vector<int> dd;
    std::vector<int> ff;
    std::vector<int> prev;
    int counter;

    color.assign(vn + 1, White);
    dd.assign(vn + 1, 0);
    ff.assign(vn + 1, 0);
    prev.assign(vn + 1, 0);

    counter = 0;
    dfsearch(gar, vn, 1, color, dd, ff, prev, counter);
    std::vector<VColor>::iterator cit = color.begin();
    for (cit++; cit != color.end(); cit++) {
        if (*cit == White) {
            dfsearch(gar, vn, std::distance(color.begin(), cit), color,
                     dd, ff, prev, counter);
        }
    }

    for (int uu = 1; uu <= vn; uu++) {
        cout << uu << " " << dd[uu] << " " << ff[uu] << std::endl;
    }
}

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

struct Node {
	int in, out;
	bool flag = false;
	vector<int> v;
};

int dfs(vector<Node>& u, int id, int d)
{
	if (u[id].flag) return d - 1;

	int a;
	u[id].in = d;
	u[id].flag = true;
	for (int i = 0; i < u[id].v.size(); i++)
	{
		d = dfs(u, u[id].v[i], d + 1);

	}
	u[id].out = d + 1;
	return d + 1;
}

int main(void)
{
	int N, id, k, x;
	Node z;
	cin >> N;
	vector<Node> u(N + 1);
	for (int i = 0; i < N; i++)
	{
		cin >> id >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> x;
			u[id].v.push_back(x);
		}
	}

	int d = 0;
	for(int i = 1; i <= N; i++) d = dfs(u, i, d + 1);

	for (int i = 1; i <= N; i++) cout << i  << " " << u[i].in << " " <<  u[i].out << endl;

	return 0;
}

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

vector<int> graph[100];
int d[100], f[100];
int visited = 0;

void dfs(int id){
    d[id] = visited++;
    for(int i = 0; i < graph[id].size(); i++)
	{
        if(graph[id][i] != id && !d[graph[id][i]] && !f[graph[id][i]])
		{
			dfs(graph[id][i]);
		}
    }
    f[id] = visited++;
}

int main(){
    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 v;
            cin >> v;
            graph[u - 1].push_back(v - 1);
        }
    }
    dfs(0);
    for(int i = 0;i < n;i++)
	{
        if(!f[i]) 
		{
			dfs(i);
		}
    }
    for(int i = 0;i < n;i++)
	{
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

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

static const int MAX_NUM = 101;

static const int NO_VISIT  = 0;
static const int NOW_VISIT = 1;
static const int END_VISIT = 2;

void DSF(int* matrix, int num)
{
    int i, j;
    int ttime = 0;
    int stime[MAX_NUM+1] = {0};
    int etime[MAX_NUM+1] = {0};
    int state[MAX_NUM+1] = {0};
    stack<int> S;
    int target, next;
    int *tmp;

    for (j = 1; j <= num; j++) {
    if (state[j] != NO_VISIT) {
        continue;
    }
    S.push(j);
    ++ttime;
    stime[j] = ttime;
    state[j] = NOW_VISIT;

    while (S.empty() == false) {
        target = S.top();
        for (i = 1; i <= num; i++) {
            tmp = matrix + MAX_NUM * target + i;
            if ((*tmp == 1) && (state[i] == NO_VISIT)) {
                *tmp = 2;
                S.push(i);
                ++ttime;
                stime[i] = ttime;
                state[i] = NOW_VISIT;
                break;
            }
        }

        if (i == num + 1) {
            S.pop();
            ++ttime;
            etime[target] = ttime;
            state[target] = END_VISIT;
        }
    }
    }

    for (i = 1; i <= num; i++) {
        printf("%d %d %d\n", i, stime[i], etime[i]);
    }

    return;
}

int main(void)
{
    int i, j;
    int num;
    int elem;
    int nume;
    int tmp;
    int matrix[MAX_NUM][MAX_NUM] = {0};

    scanf("%d", &num);

    for (i = 0; i < num; i++) {
        scanf("%d %d", &elem, &nume);
        for (j = 0; j < nume; j++) {
            scanf("%d", &tmp);
            matrix[elem][tmp] = 1;
        }
    }

    DSF(&matrix[0][0], num);

    return 0;
}