Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

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

void dfs(int cur, vector<vector<int> > arr, int d[], int f[], int &time, int n, bool psd[]){
    d[cur] = time;
    time++;
    psd[cur] = true;
    for(int dst = 0; dst < n; dst++){
        if(arr[cur][dst] == 1 && !psd[dst]){
            dfs(dst,arr,d,f,time,n,psd);
        }
    }
    f[cur] = time;
    time++;
}

int main(){
    int n;
    scanf("%d",&n);
    vector<vector<int> > arr(n,vector<int>(n));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            arr[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        int u,k;
        scanf("%d %d",&u,&k);
        for(int j = 0; j < k; j++){
            int v;
            scanf("%d",&v);
            arr[u-1][v-1] = 1;
        }
    }
    int d[n],f[n],time = 1;
    bool psd[n];
    for(int i = 0; i < n; i++){
        psd[i] = false;
    }
    for(int cur = 0; cur < n; cur++){
        if(!psd[cur]){
            dfs(cur,arr,d,f,time,n,psd);
        }
    }
    for(int id = 0; id < n; id++){
        printf("%d %d %d\n", id+1, d[id], f[id]);
    }
}

C++: #include <stdio.h>
#include <iostream>
using namespace std;

class Adjl{
private:
	int u;
	int k;
	Adjl **next;
protected:
	int d;
	int f;
public:
	Adjl(int u);
	~Adjl(){ if (next != NULL) delete[] next; }
	void setV(int k, Adjl *vk);
	int depthFirstSearch(int time);
	void print();
};

Adjl::Adjl(int u)
{
	this->u = u;
	k = 0;
	next = NULL;
	d = 0;
	f = 0;
}

void Adjl::setV(int k, Adjl *vk)
{
	if (this->k == 0) next = new Adjl*[k];
	next[this->k] = vk;
	(this->k)++;
}

int Adjl::depthFirstSearch(int time)
{
	time++;
	d = time;
	for (int i = 0; i < k; i++) {
		if (next[i]->d == 0) {
			time = next[i]->depthFirstSearch(time);
		}
	}
	time++;
	f = time;
	return time;
}

void Adjl::print()
{
	cout << u << " " << d << " " << f << endl;
}

int main(void)
{
	int n;
	cin >> n;
	
	Adjl **adjl = new Adjl*[n];
	int check[100] = {0};

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		if (check[i] == 0) {
			adjl[i] = new Adjl(u);
			check[i] = 1;
		}
		check[i] = 1;
		for (int j = 0; j < k; j++) {
			int vk;
			cin >> vk;
			if (check[vk - 1] == 0) {
				adjl[vk - 1] = new Adjl(vk);
				check[vk - 1] = 1;
			}
			adjl[i]->setV(k, adjl[vk - 1]);
		}
	}

	adjl[0]->depthFirstSearch(0);

	for (int i = 0; i < n; i++) {
		adjl[i]->print();
	}

	delete[] adjl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

using Graph = vector<vector<int>>;
Graph G;

vector<int> d, f;

int dfs(int v, int t) {
    if(d[v]==0) d[v]=t;
    int res = t;
    for(const auto nv: G[v]) {
        if (d[nv]) continue;
        res = dfs(nv, res+1);
    }
    return f[v] = ++res;
}

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

    int n; cin >> n;
    G.resize(n);
    rep(i, n) {
        int x, k; cin >> x >> k;
        x--;
        rep(j, k) {
            int v; cin >> v; v--;
            G[x].push_back(v);
        }
    }

    d.assign(n, 0); f.assign(n, 0);

    int cur = 1;
    rep(i, n) {
        if (!d[i]) {
            cur = dfs(i, cur);
            cur++;
        }
    }
    rep(i, n) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

using ll = long long;
using namespace std;

/* initialize */
int color[100], nt[100], d[100], f[100], tt;
int A[100][100];
int n;

int next(int u){
    for (int v = nt[u]; v < n; ++v) {
        nt[u] = v + 1;
        if( A[u][v]) return v;
    }
    return -1;
}

void dfs_visit(int r){
    for (int i = 0; i < n; ++i) nt[i] = 0;
    stack<int> S;
    S.push(r);
    color[r] = 1;
    d[r] += ++tt;

    while (!S.empty()){
        int u = S.top();
        int v = next(u);
        if (v != -1){
            if (color[v] == 0){
                color[v] = 1;
                d[v] = ++tt;
                S.push(v);
            }
        } else{
            S.pop();
            color[u] = 2;
            f[u] = ++tt;
        }
    }
}
void dfs(){
    for (int i = 0; i < n; ++i) {
        color[i] = 0;
    }
    tt = 0;

    for (int u = 0; u < n; ++u) {
        if (color[u] == 0) dfs_visit(u);
    }
    for (int i = 0; i < n; ++i) {
        cout << i+1 << " " << d[i] << " " << f[i] << "\n";
    }
}
/* main */
int main() {
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) A[i][j] = 0;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            cin >> v;
            A[u-1][v-1] = 1;
        }
    }

    dfs();
    return 0;
}

C++: #include<cstdio>
#define WHITE 0
#define GRAY  1
#define BLACK 2

void InitializeBoolMatrix(int nmbr_of_rows, int nmbr_of_columns, bool mtrx[][100]){
	for (int row = 0; row < nmbr_of_rows; ++row) {
		for (int column = 0; column < nmbr_of_columns; ++column)
			mtrx[row][column] = false;
	}
}

void ListToMatrix(int number_of_vertices, bool mtrx[][100]){
	int vertex_from, vertex_to, degree_out;	
	for (int vertex_i = 0; vertex_i < number_of_vertices; ++vertex_i) {
		scanf("%d %d", &vertex_from, &degree_out);
		vertex_from--; //0?????????????????????
		for (int vertex_out_i = 0; vertex_out_i < degree_out; ++vertex_out_i) {
			scanf("%d", &vertex_to);
			vertex_to--; //0?????????????????????
			mtrx[vertex_from][vertex_to] = true;
		}
	}
}

bool adjmtrx[100][100];

void BuildAdjacencyMatrix(int n){
	InitializeBoolMatrix(n, n, adjmtrx);
	ListToMatrix(n, adjmtrx);
}

int color[100];
int time;
int discoveredtime[100];
int finishedtime[100];

void Dfs(int present_vertex, int n){
	int pv = present_vertex;
	color[pv] = GRAY;
	discoveredtime[pv] = ++time;
	for(int v = 0;v < n;v++){
		if(adjmtrx[pv][v] && color[v] == WHITE){
			Dfs(v, n);
		}
	}
	color[pv] = BLACK;
	finishedtime[pv] = ++time;
}

void DfsInit(int n){
	for (int i = 0; i < n; ++i)
		color[i] = WHITE;
	time = 0;
}

int main(){
	int number_of_vertices;
	scanf("%d", &number_of_vertices);
	int n = number_of_vertices;
	BuildAdjacencyMatrix(n);
	DfsInit(n);
	for (int vertex_i = 0; vertex_i < n; ++vertex_i){
		if(color[vertex_i] == WHITE)
		Dfs(vertex_i, n);
	}
	for (int id = 0; id < n; ++id)
		printf("%d %d %d\n", id+1, discoveredtime[id], finishedtime[id]);
	return 0;
}