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<iostream>
using namespace std;
#include<stdio.h>

int G[101][102];
int found[101];
int comp[101];   // complete.
int t;  // time.

typedef struct box{ int val; box* next; } box_t;  // stack.

box_t* init()
{
    box_t* head = new box_t;
    head->val = -1;
    head->next = NULL;
    return head;
}

bool isEmpty(box_t* head){ return (head->next == NULL ? true : false); }

box_t* push(box_t* head, int data)
{
    box_t* box = new box_t;
    box->val = data;
    box->next = head->next;
    head->next = box;
    return box;
}

int pop(box_t* head)
{
    if(isEmpty(head)){ return -1; }
    box_t* box = head->next;
    int val;
    head->next = box->next;
    val = box->val;
    delete box;
    return val;
}

int front(box_t* head)
{
    int val;
    if(isEmpty(head)){ return -1; }
    val = head->next->val;
    return val;
}

box_t* stack = init();

void search_loop(int i)
{
    int j, k;
    while(1){
        if(found[i] == 0){
            t++; found[i] = t;
            push(stack, i);
        }
        for(k = G[i][0]; G[i][k] != 0 && found[G[i][k]] != 0; k++);
        if(G[i][k] == 0){
            if(isEmpty(stack)){ return; }
            else{
                j = pop(stack);
                t++; comp[j] = t;
                i = front(stack);
            }
        }else{
            G[i][0] = k + 1;
            i = G[i][k];
        }
    };
    return;
}

int main()
{
    int n, i, j, a, b, e;
    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        G[i][0] = 1;
        for(j = 1; j <= n + 1; j++){ G[i][j] = 0; } }

    for(i = 1; i <= n; i++){
        scanf("%d %d", &a, &e);
        for(j = 1; j <= e; j++){
            scanf("%d", &b); G[a][j] = b; } }  // adjacent representation.

    for(i = 1; i <= n; i++){ found[i] = 0; comp[i] = 0; }
    t = 0;
    while(1){
        for(i = 1; i <= n; i++){
            if(found[i] == 0) break;
        }
        if(i > n) break;
        search_loop(i);
    };

    for(i = 1; i <= n; i++){
        cout << i << " " << found[i] << " " << comp[i] << endl;
    }
    return 0;
}

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

int N;
int G[101][101];
int visited[101];

int start[101], complete[101];

int dfs(int v, int t) {
    visited[v] = 1;
    start[v] = t;
    int nt = t+1;
    for (int j = 0; j <= N; ++j) {
        if (!visited[j] && G[v][j]) {
            nt = dfs(j, nt);
        }
    }
    complete[v] = nt;
    return nt+1;
}

int main() {
    cin >> N;
    for (int j = 0; j <= N; ++j) for (int k = 0; k <= N; ++k) G[j][k] = 0;
    for (int j = 0; j <= N; ++j) visited[j] = 0;
    for (int _ = 0; _ < N; ++_) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v; cin >> v;
            G[u][v] = 1;
        }
    }

    int tt = 1;
    for (int j = 1; j <= N; ++j) {
        if (!visited[j]) tt = dfs(j, tt);
    }

    for (int j = 1; j <= N; ++j) {
        cout << j << " " << start[j] << " " << complete[j] << endl;
    }

    return 0;
}

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

const int NIL = -1;
const int MAX = 20001;

int G[101][101];
int color[101], d[101], f[101];
int t = 0;

void dfs(int u, int n)
{
	color[u] = 1;
	d[u] = ++t;
	for (int v = 1; v <= n; v++) {
		if (G[u][v] && color[v] == 0)
			dfs(v, n);
	}
	color[u] = 1;
	f[u] = ++t;
}

int main(void)
{
	int n, k, v, u;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int i = 0; i < k; i++) {
			cin >> v;
			G[u][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (color[i] == 0)
			dfs(i, n);
	}
	for (int i = 1; i <= n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

C++: // ALDS1_11_B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

vector<vector<int>> node(101);
vector<int> setu(101);
vector<bool> seen(101,false); 
vector<int> start(101,0);
vector<int> goal(101,0);
int t=0;
void dfs(int x){
    if(seen[x]==true) return;
    seen[x]=true;
    t++;
    start[x]=t;
    rep(i,setu[x]){
        dfs(node[x][i]);
    }
    t++;
    goal[x]=t;
}

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

    int n;
    cin>>n;
    rep(i,n){
        int u,k;
        cin>>u>>k;
        rep(j,k){
            int v;
            cin>>v;
            node[u].push_back(v);
            setu[u]=k;
        }
    }
    for(int i=1;i<=n;i++){
        dfs(i);
    }
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<start[i]<<" "<<goal[i]<<endl;
    }
    return 0;
}

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, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const int MAX = 105;

int t = 0;
pair<int, int> ans[MAX];
bool seen[MAX];
vector<int> to[MAX];

void dfs(int u) {
  if (seen[u]) return;
  seen[u] = true;
  ans[u].first = ++t;
  for (int v: to[u]) {
    dfs(v);
  }
  ans[u].second = ++t;
}

int main() {
  int n, u, k, v;
  cin >> n;
  rep(i, n) {
    cin >> u >> k;
    rep(j, k) {
      cin >> v;
      to[u].push_back(v);
    }
  }

  rep(i, n+1) seen[i] = false;
  FOR(i, 1, n+1) sort(to[i].begin(), to[i].end());

  FOR(i, 1, n+1) dfs(i);

  FOR(i, 1, n+1) {
    cout << i << " " << ans[i].first << " " << ans[i].second << endl;
  }



  
  return 0;
}

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

int main()
{
 int i;
}