Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

C++: #include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int n;
VI g[110];
int d[110];
int f[110];


void dfs(int v, int p, int& t){
    d[v] = t;
    t++;
    rep(i, 0, SZ(g[v])) if(g[v][i] != p and d[g[v][i]] == 0) dfs(g[v][i], v, t);
    f[v] = t;
    t++;
}


signed main(){
    cin >> n;
    rep(i, 0, n){
        int u, k;
        cin >> u >> k;
        u--;
        int v;
        rep(j, 0, k) cin >> v, g[u].pb(v-1);
    }

    int t = 1;
    rep(i, 0, n) if(d[i] == 0) dfs(i, -1, t);

    rep(i, 0, n) cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;

    return 0;
}

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

using namespace std;

#define MAX_N (105)

vector<int> G[MAX_N];
bool arrived[MAX_N];
int d[MAX_N];
int f[MAX_N];
int n;
int t;
void dfs( int cur ) {
    t++;
    d[cur] = t;

    for ( int i = 0; i < G[cur].size(); i++ ) {
	int next = G[cur][i];
	if ( !arrived[next] ) {
	    arrived[next] = true;
	    dfs( next );
	}
    }

    t++;
    f[cur] = t;

    return;
}

int main()
{
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);
	u--;
	for ( int j = 0; j < k; j++ ) {
	    int v;
	    scanf("%d", &v);
	    v--;
	    G[u].push_back(v);
	}
    }

    t = 0;
    for ( int i = 0; i < n; i++ ) {
	if ( !arrived[i] ) {
	    arrived[i] = true;
	    dfs(i);
	}
    }


    for ( int i = 0; i < n; i++ ) {
	printf("%d %d %d\n", i+1, d[i], f[i]);
    }

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
#include <list>
using namespace std;

int n;

struct Node{
public:
  int id, d, f, flag;
  vector<int> c;
  Node(){d = 1000000007;f = flag = 0;}
};

vector<Node> v(101);

void rec(int id, int &t){
  if(v[id].flag)return;
  else          v[id].flag = 1;
  v[id].d = min(v[id].d, ++t);
  for(int i=0;i<v[id].c.size();i++) {
    rec(v[id].c[i], t);
  }
  v[id].f = max(v[id].f, ++t);
}


bool asc(const Node &right, const Node &left){return right.id < left.id;}

int main(){
  cin >> n;
  
  v[0].id = 0;  
  for(int i=1;i<=n;i++){
    int t, a;  cin >> a >> t;
    vector<int> b(t);
    for(int j=0;j<t;j++){
      int val;cin >> val;
      b[j] = val;
    }
    v[a].id = a;
    v[a].c = b;
  }
  sort(v.begin(), v.end(), asc);

  int ti = 0;
  for(int i=1;i<=n;i++){
    rec(i, ti);
  }

  for(int i=1;i<=n;i++){
    printf("%d %d %d\n", v[i].id, v[i].d, v[i].f);
  }
  return 0;
}

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

using namespace std;
struct node {
    node() {};
    node(int i, int n, int* xs) : id {i}, ns {vector<int>(xs, xs+n)} {
        delete xs;
    };
    int id;
    vector<int> ns;
    int in_time;
    int out_time;
};

int dfs(map<int, node*> graph, int time, int id){
    node* n = graph[id];
    if(n->in_time > 0){
        return time;
    }
    n->in_time = ++time;
    vector<int> ns = n->ns;
    for(auto it = ns.begin(); it != ns.end(); ++it){
        time = dfs(graph, time, *it);
    }
    n->out_time = ++time;
    return time;
}

int main(){
    int n;
    cin >> n;
    map<int, node*> graph {};
    int st = 1000000000;
    for(int i = 0; i < n; ++i){
        int id;
        cin >> id;
        st = min(st, id);
        int k;
        cin >> k;
        int* ns = new int[k];
        for(int j = 0; j < k; ++j){
            cin >> ns[j];
        }
        graph[id] = new node(id, k, ns);
    }
    for(auto it = graph.begin(); it != graph.end(); ++it){
        pair<int, node*> p = *it;
        if(p.second->in_time){
            continue;
        }
        dfs(graph, 0, p.first);
    }
    for(auto it = graph.begin(); it != graph.end(); ++it){
        pair<int, node*> p = *it;
        cout << p.first << ' ' << p.second->in_time << ' ' << p.second->out_time << endl;
    }
}

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

int n, t = 0;
int A[101][101];
int d[101], f[101];

void dfs(int r) {
	d[r] = ++t;
	for (int i = 1; i <= n; i++) {
		if (A[r][i] == 1 && d[i] == 0) dfs(i);
	}
	f[r] = ++t;
	return;
}

int main() {
	int u, v, l;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		d[i] = f[i] = 0;
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			A[i][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++) {
		cin >> u >> l;
		for (int j = 0; j < l; j++) {
			cin >> v;
			A[u][v] = 1;
		}
	}

	dfs(1);

	for (int i = 1; i <= n; i++) {
		cout << i << ' ' << d[i] << ' ' << f[i] << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#define Lens 105
using namespace std;
int N;
int A[Lens][Lens];
int S[Lens], E[Lens];
int sum = 0;
char c[Lens];

void dns(int i)
{
	sum++;
	S[i] = sum;
	c[i] = 'g';
	for (int j = 1; j <= N; j++)
	{
		if (A[i][j] == 1 && c[j] == 'w')
			dns(j);
	}
	sum++;
	E[i] = sum;
	c[i] = 'b';
}

int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		int k, n;
		cin >> k >> n;
		c[i] = 'w';
		for (int i = 0; i < n; i++)
		{
			int j;
			cin >> j;
			A[k][j] = 1;
		}
	}
	/*
	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= N; j++)
		{
			if (j > 1)
				cout << ' ';
			cout << A[i][j];
		}
		cout << endl;
	}
	*/
	dns(1);
	for (int i = 1; i <= N; i++)
	{
		cout << i << ' ' << S[i] << ' ' << E[i] << endl;
	}
	return 0;
}