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>
#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;
}

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

struct Vertex {
	int id;
	vector<int> vertices;
	int visited;
	int completed;
};

int getNext(Vertex vertices[], int id){
	Vertex v = vertices[id-1];
	int size = v.vertices.size();
	for(int i=0;i<size;i++){
		int nId = v.vertices[i];
		if (vertices[nId-1].visited==-1){
			return nId;
		}
	}
	return -1;
}

void dfs(int n, Vertex vertices[]){
	
	int time = 0;

	for(int i=0;i<n;i++){
		Vertex cur=vertices[i];
		stack<int> st;
		if(cur.visited==-1){
			st.push(cur.id);
		}
		while(!st.empty()){
			int id=st.top();
			if(vertices[id-1].visited==-1){
				vertices[id-1].visited=++time;
			}
			int nId=getNext(vertices,id);
			if(nId!=-1){
				vertices[nId-1].visited=++time;
				st.push(nId);
			} else {
				vertices[id-1].completed=++time;
				st.pop();
			}
		}
	}
}

int main(){
	int n;
	cin >> n;
	Vertex vertices[n];
	for(int i=0;i<n;i++){
		int id;
		cin >> id;
		vertices[i].id = id;
		vertices[i].visited = -1;
		vertices[i].completed = -1;
		int cnt;
		cin >> cnt;
		for(int j=0;j<cnt;j++){
			cin >> id;
			vertices[i].vertices.push_back(id);
		}
	}
	
	dfs(n,vertices);
	
	for(int i=0;i<n;i++){
		Vertex v = vertices[i];
		cout << v.id << " ";
		cout << v.visited << " ";
		cout << v.completed << endl;
	}
	return 0;
}

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

int a[100][100];
int n,p,q,r;
int T[100],F[100];
int Time = 0;
void dfs(int cur) {
	T[cur] = Time;
	Time += 1;
	cerr << "visiting " << cur << ' ' << Time << endl;
	for (int dst=0; dst < n; ++dst) {
		if(a[cur][dst] == 1 && T[dst] == -1) {
			dfs(dst);
		}
	}
	F[cur] = Time;
	Time += 1;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> p >> q;
		T[i] = -1;
		for (int j=0; j<q; ++j) {
			cin >> r;
			a[p-1][r-1] = 1;
		}
	}
	dfs(0);
	for (int i=0; i<n; ++i) {
		cout << i+1 << " " << T[i]+1 << " " << F[i]+1 << endl;
	}
}

C++: #include <iostream>
#include <stack>
using namespace std;
static const int N=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

//??¶????????°
int n;
//?????\??????
int M[N][N];
//??°?????¶???????¢????
int color[N];
//??\??¶????????°??¶???
int d[N];
//??\??¶???????????¶???
int f[N];
//??¶???
int tt;
//???????????????????????????????????????
//?????¨?????????????????¨????????\??????????????????
int nt[N];

//????????????????????????u?????????v
int next(int u){
    for(int v=nt[u];v<n;v++){
        nt[u]=v+1;
        if(M[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]=GRAY;
    //?????°??¶???
    d[r]=++tt;

    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1&&color[v]==WHITE){
            color[v]=GRAY;
            d[v]=++tt;
            S.push(v);
        }
        else{
            //????????????
            S.pop();
            color[u]=BLACK;
            f[u]=++tt;
        }
    }
}

void dfs(){
    //????§????
    for(int i=0;i<n;i++)
        color[i]=WHITE;
    tt=0;

    //??\????????????u?????????????????±?????????????´¢
    for(int u=0;u<n;u++)
        if(color[u]==WHITE)
            dfs_visit(u);

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

int main(){
    int u,k,v;

    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            M[i][j]=0;

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

    dfs();
}

C++: #include<bits/stdc++.h>
using namespace std;

vector<int> d, f;
vector<vector<int>> edge;
int t = 0;

void dfs(int s) {
    d[s] = ++t;
    for (int u : edge[s]) {
        if (d[u] == -1)
            dfs(u);
    }
    f[s] = ++t;
}

int main() {
    int n;
    cin >> n;
    d.resize(n, -1);
    f.resize(n);
    edge.resize(n);
    for (int i = 0; i < n; ++i) {
        int id, k;
        cin >> id >> k;
        if (id != i + 1) exit(1);
        if (!k) continue;

        edge[i].resize(k);
        for (int j = 0; j < k; ++j) {
            cin >> edge[i][j];
            --edge[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        if (d[i] == -1)
            dfs(i);

        cout << (i + 1) << " " << d[i] << " " << f[i] << "\n";
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n, t;
vector< vector<int> > edges(100);
vector< pair<int,int> > ans(100);
vector< bool > vis(100, false);

void dfs(int v){
  t++;
  vis[v] = true;
  ans[v].first = t;
  for(int i : edges[v])
    if(vis[i] == false)
      dfs(i);
  t++;
  ans[v].second = t;
}

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

  for(int i = 0; i < n; i++){
    int k;
    cin >> k >> k;
    for(int j = 0; j < k; j++){
      int to;
      cin >> to;
      edges[i].push_back(to-1);
    }
  }

  t = 0;
  for(int i = 0; i < n; i++){
    if(vis[i] == false)
      dfs(i);
  }
  for(int i = 0; i < n; i++){
    cout << i + 1 << ' ' <<  ans[i].first << ' ' << ans[i].second << endl;
  }
}