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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

using Graph = vector<vector<int>>;

int dfs(Graph &graph, vector<int> &d, vector<int> &f, int cur, int time)
{
    if(d[cur] > 0) return time;
    d[cur] = time;
    time++;
    for(int child : graph[cur])
    {
        time = dfs(graph, d, f, child, time);
    }
    f[cur] = time;
    time++;
    return time;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    Graph graph(n);
    REP(i, n) 
    {
        int u, k;
        cin >> u >> k;
        REP(j, k) 
        {
            int v;
            cin >> v;
            graph[u-1].push_back(v-1);
        }
    }

    vector<int> d(n, 0), f(n, 0);
    int time = 1;
    REP(i, n)
    {
        if(d[i] > 0) continue;
        time = dfs(graph, d, f, i, time);
    }

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

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

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;
    cin >> 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++){
        cin >> a >> e;
        for(j = 1; j <= e; j++){
            cin >> 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<bits/stdc++.h>
using namespace std;

struct Graph{
	
	vector<char> seen;
	vector<vector<int>> e;
	vector<int> time1,time2; 
	Graph(int n) : seen(n),e(n),time1(n),time2(n){}
	
	void dfs(int v, int &t){
		t++;
		time1.at(v) = t;
		seen.at(v) = 1;
		for(auto nv:e.at(v)) {
			if(seen.at(nv)==1) continue;
			dfs(nv,t);
		}
		t++;
		time2.at(v) = t;
		return;
	}
	
};

int main() {
	
	int n;
	cin >> n;
	Graph graph(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;
			v--;
			graph.e.at(i).push_back(v);
		}
	}
	
	int t={};
	for(int i=0; i<n; i++){
		if(graph.seen.at(i)!=1) graph.dfs(i,t);
	}
	
	for(int i=0; i<n; i++){
		cout << i+1 << ' ' << graph.time1.at(i) << ' ' << graph.time2.at(i) << endl;
	}
	
	
}

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

#define MAX 101

using namespace std;

int visited[MAX],d[MAX],f[MAX],called[MAX];
int tt=0;
vector<int> G[MAX];
stack<int> S;

int getNext(int u){
  if(called[u]>=G[u].size()) return -1;
  else{
    int x=G[u][called[u]];
    called[u]++;
    return x;
  }
}


void dfs(int u){
  S.push(u);
  visited[u]=1;
  d[u]=++tt;
  while(S.empty()==false){
    int x=S.top();
    int v=getNext(x);
    if(v!=-1){
      if(visited[v]==0){
        visited[v]=1;
        d[v]=++tt;
        S.push(v);
      }
    }else{
      S.pop();
      visited[x]=1;
      f[x]=++tt;
    }
  }
}

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

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<vector<int> > v(n);
	vector<int> k(n);
	int x;
	rep(i,n){
		cin>>x;
		cin>>k[i];
		v[i].resize(k[i]);
		rep(j,k[i]){
			cin>>v[i][j];
			v[i][j]--;
		}
	}
	vector<int> a(n),b(n);
	stack<int> s;
	int count=1;
	s.push(0);
	a[0]=1;
	while(s.empty()==0){
		count++;
		int x=s.top();
		rep(i,k[x]){
			if(a[v[x][i]]==0){
				s.push(v[x][i]);
				a[v[x][i]]=count;
				break;
			}
			if(i==k[x]-1){
				k[x]=0;
			}
		}
		if(k[x]==0){
				b[x]=count;
				s.pop();
		}
	}

	rep(i,n){
		cout<<i+1<<" "<<a[i]<<" "<<b[i]<<endl;;
	}

		



	return 0;
}