Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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;
}