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)
	dfs(&g, &d, &f, 1, 1)

	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 <iostream>
#include <vector>
#include <set>
#include <unordered_map>
//#include "../cxx-prettyprint/prettyprint.hpp"

int timer = 0;
std::unordered_map<int, std::vector<int>> Adj;
std::set<int> nodes_unvisited;
std::unordered_map<int, int> discovered_time;
std::unordered_map<int, int> finished_time;

int dfs(int u) {
    nodes_unvisited.erase(u);
    discovered_time[u] = ++timer;
    for (int v : Adj[u]) {
        if (nodes_unvisited.find(v) != nodes_unvisited.end()) {
            dfs(v);
        }
    }
    finished_time[u] = ++timer;
}

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

    for (int i = 0; i < n; i ++) {
        int u, k;
        std::cin >> u >> k;
        std::vector<int> V(k);
        for (auto& v : V) {
            std::cin >> v;
        }
        Adj[u] = V;
    }

    for (int i = 1; i <= n; i ++) {
        nodes_unvisited.insert(i);
    }

    while (!nodes_unvisited.empty()) {
        int u = *nodes_unvisited.begin();
        dfs(u);
    }

    for (int i = 1; i <= n; i ++) {
        std::cout << i << " " << discovered_time[i]
            << " " << finished_time[i] << std::endl;
    }
}

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

using namespace std;

static const int MAX = 100;
static const int WHITE = 1;
static const int GRAY = 2;
static const int BLACK = 3;
static const int NIL = -1;

class DFS{
private:
    int color[MAX];
    int M[MAX][MAX];
    stack<int> S;
    int n;
    int discovery[MAX];
    int finish[MAX];
    int time = 0;
    int next_vertex[MAX];
public:
    DFS()
    {
        cin >> n;
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                M[i][j] = 0;
        int vertex;
        int degree;
        for(int i = 0; i < n; i++)
        {
            color[i] = WHITE;
            next_vertex[i] = 0;
            cin >> vertex;
            cin >> degree;
            int to_v;
            for(int j = 0; j < degree; j++)
            {
                cin >> to_v;
                M[vertex - 1][to_v - 1] = 1;
            }
        }
    }

    int next(int u)
    {
        for(int v = next_vertex[u]; v < n; v++)
        {
            next_vertex[u] = v + 1;
            if(M[u][v]) return v;
        }
        return NIL;
    }

    void dfs_visit(int start)
    {
        for(int i = 0; i < n; i++)
            next_vertex[i] = 0;

        S.push(start);
        color[start] = GRAY;
        discovery[start] = ++time;

        while(S.size() != 0)
        {
            int u = S.top();
            int v = next(u);
            if(v != NIL)
            {
                if(color[v] == WHITE)
                {
                    color[v] = GRAY;
                    discovery[v] = ++time;
                    S.push(v);
                }
            }
            else
            {
                S.pop();
                color[u] = BLACK;
                finish[u] = ++time;
            }
        }
    }

    void dfs()
    {
        for(int u = 0; u < n; u++)
        {
            if(color[u] == WHITE)
                dfs_visit(u);
        }

        for(int i = 0; i < n; i++)
            cout << i + 1 << " " << discovery[i] << " " << finish[i] << endl;
    }
};

int main()
{
    DFS dfs;
    dfs.dfs();
}

C++: #include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;

long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}
long comb(int N,int K)
{
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

long hcomb(int N, int K){
    return comb(N+K-1, N-1);
}


int t = 1;
void dfs(const vector<vector<int> > &G, int v, vector<bool> &seen, VI &d, VI &f) {
    seen[v] = true; // v を訪問済にする
    d[v] = t;

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v] == false) { // next_v が探索済だったらスルー
          	t++;
        	dfs(G, next_v, seen, d, f); // 再帰的に探索     	
        }
    }
    t++;
    f[v] = t;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

    int n, u, k;
    cin >> n;
    VVI G(n);
    REP(i,n){
        cin >> u >> k;
        if (k){
            G[i].resize(k);
            REP(j,k) {
                cin >> G[i][j];
                G[i][j]--;
            }
          	sort(ALL(G[i]));
        }
    }

    vector<bool> seen(n,false);

    VI d(n,0), f(n,0);

  	REP(i,n){
      	if (d[i] == 0){
        	dfs(G, i, seen, d, f);
          	t++;
        }
    }

    REP(i,n) cout << i+1 << " " << d[i] << " " << f[i] << endl;

}

C++: #include <cstdio>

typedef struct Node {
    int id;
    int d;
    int f;
    int count;
} Node;


int count(int id, int now, Node *node, int a[101][100]){
    if(node[id].d == 0) node[id].d = now;
    else return now - 1;
    if(node[id].f != 0) return now - 1;
    for(int i = 0; i < node[id].count; ++i){
        int nextId = a[id][i];
        now = count(nextId, now + 1, node, a);
    }
    node[id].f = now + 1;
    return node[id].f;
}

int main(){
    int n;
    std::scanf("%d", &n);
    Node node[101];
    int a[101][100];
    for(int i = 1; i <= n; ++i){
        int id;
        std::scanf("%d", &id);
        node[id].id = id;
        std::scanf("%d", &node[id].count);
        for(int j = 0; j < node[id].count; ++j){
            std::scanf("%d", &a[id][j]);
        }
    }
    int now = 0;
    for(int i = 1; i <= n; ++i){
        now = count(i, now + 1, node, a);
    }
    for(int i = 1; i <= n; ++i){
        std::printf("%d %d %d\n", node[i].id, node[i].d, node[i].f);
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define N 105
int n,cnt;
int graph[N][N];
int ans1[N],ans2[N];
bool checked[N];
void dfs(int i){
    if(checked[i]) return;
    checked[i] = true;
    ans1[i] = cnt++;
    for(int j = 0; j < n; j++){
        if(graph[i][j]) dfs(j);
    }
    ans2[i] = cnt++;
}

signed main() {
    cin >> n;
    for(int i = 0; i < n; i++){
        int a,b,c;
        cin >> a >> b;
        a--;
        for(int j = 0; j < b; j++){
            cin >> c;
            c--;
            graph[a][c] = 1;
        }
    }

    cnt = 1;
    for(int i = 0; i < n; i++){
        if(!checked[i]) dfs(i);
    }
    for(int i = 0; i < n; i++){
        cout << i + 1 << " " << ans1[i] << " " << ans2[i] << endl;
    }
}