Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()

int d[110];
int f[110];
vector<int> edge[110];
int t=0;
void dfs(int now){
    sort(All(edge[now]));
    if(edge[now].size()==0){
        t++;
        f[now]=t;
    }else{
        for(int i=0;i<edge[now].size();i++){       
            if(d[edge[now][i]]==-1){
                t++;
                d[edge[now][i]]=t;
                dfs(edge[now][i]);
            }
            if(i==edge[now].size()-1){
                t++;
                f[now]=t;
            }
        }
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    fill(d,d+110,-1);
    fill(f,f+110,-1);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            int x;
            cin>>x;
            edge[u].push_back(x);
        }
    }
    for(int i=1;i<=n;i++){
        if(d[i]==-1){
            t++;
            d[i]=t;
            dfs(i);
        }
    }
    for(int i=1;i<=n;i++){
        cout<<i<<' '<<d[i]<<' '<<f[i]<<endl; 
    }

}

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

int n, G[101][101], S[101], T[101];

int dfs(int p, int s) {
    if (S[p] != 0) return 0;
    S[p] = s;
    s++;
    for (int i = 0; i < n; i++) {
        if (G[p][i] == 1) {
            s = max(s, dfs(i, s) + 1);
        }
    }
    T[p] = s;
    return s;
}


int main(void) {
    int u, k, v, s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v;
            G[u - 1][v - 1] = 1;
        }
    }

    s = 0;
    for (int i = 0; i < n; i++)
        if (S[i] == 0) s = dfs(i, s);

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

    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

typedef pair<int,int> P;

vector<int> g[100];
int ans[100][2]; //[i][0] 到着　　[i][1] 終了
int t=1;

void dfs(int v){
	ans[v][0] = t;
	t++;
	for(int i=0;i<g[v].size();i++){
		dfs(g[v][i]);
		t++;
	}
	ans[v][1] = t;

	return;
}

int main(){
	//ios::sync_with_stdio(false);
	//cin.tie(0);

	int n;
	cin >> n;
	
	for(int i=0;i<n;i++){
		int u, nume;
		cin >> u >> nume;

		int v;
		for(int j=0;j<nume;j++){ //jは回数数えるだけ
			cin >> v;
			g[u-1].push_back(v-1);
		}
	}

//	for(int i=0;i<n;i++){
//		for(int j=0;j<g[i].size();j++){
//			cout << g[i][j] + 1 << " ";
//		}
//		cout << "\n";
//	}

	dfs(0);
	
	for(int i=0;i<n;i++){
		cout << i+1 << " " << ans[i][0] << " " << ans[i][1] << "\n";
	}

	return 0;
}

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

vector<vector<int>> graph;
vector<pair<int, int>> timestamp;
int time__=0;

void dfs(int v){
  if (timestamp[v].first == 0)
    timestamp[v].first = ++time__;
  else
    return;
  for (int i=0;i<graph[v].size();++i){
    dfs(graph[v][i]);
  }
  timestamp[v].second = ++time__;
}

int main(){
  int n;
  cin >> n;
  graph.resize(n+1); timestamp.resize(n+1);
  for (int i=0;i<n;++i){
    int id,k;
    cin >> id >> k;
    for(int j=0;j<k;++j){
      int temp;
      cin >> temp;
      graph[i].push_back(temp-1);
    }
  }

  for (int i=0;i<n;i++)
    dfs(i);

  for (int i=0;i<n;i++){
    cout << i+1 << " " <<timestamp[i].first << " " << timestamp[i].second << endl;
  }

  return 0;
}

C++: #include <vector>
#include <iostream>
using namespace std;
int n, u, k, v, t, d[100][2]; vector<int> g[100];
void rec(int pos) {
	d[pos][0] = ++t;
	for(int i = 0; i < g[pos].size(); i++) {
		if(!d[g[pos][i]][0]) rec(g[pos][i]);
	}
	d[pos][1] = ++t;
}
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
		for(int j = 0; j < k; j++) cin >> v, g[u - 1].push_back(v - 1);
	}
	rec(0);
	for(int i = 0; i < n; i++) cout << i + 1 << ' ' << d[i][0] << ' ' << d[i][1] << endl;
}

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

using namespace std;

int n;
int V[105][105];
vector<int> d(105, 0), f(105, 0);
int t = 0;

void dfs(int x) {
	bool p = false;
	if (d[x] != 0) p = true;
	if (d[x] == 0) {
		t++;
		d[x] = t;
	}
	for (int j = 1; j <= n; j++) {
		if (V[x - 1][j - 1] == 1 && d[j] == 0) {
			dfs(j);
		}
	}
	t++;
	if (p) t--;
	if (f[x] == 0) f[x] = t;
}


int main() {
	cin >> n;
	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			V[i][j] = 0;
		}
	}
	for (int i = 0; i<n; i++) {
		int p, m;
		cin >> p >> m;
		for (int j = 0; j<m; j++) {
			int q;
			cin >> q;
			V[p - 1][q - 1] = 1;
		}
	}
	for (int i = 0; i<n; i++) {
		dfs(i + 1);
	}
	for (int i = 0; i<n; i++) {
		cout << i + 1 << " " << d[i + 1] << " " << f[i + 1] << endl;
	}
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef int ll;
typedef pair<ll, ll> P;

ll N = 100;
vector<ll> ans1;
vector<ll> ans2;
vector<bool> seen;
ll C = 0;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}


void dfs(vector< vector<ll> > &G, int v) {
  seen[v] = true;
  // v から行ける各頂点 next_v について
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue; // next_v が探索済だったらスルー
    ans1[next_v] = ++C;
    //printf("ans1[%d] = %d\n", next_v+1, C);
    dfs(G, next_v); // 再帰的に探索
    ans2[next_v] = ++C;
    //printf("ans2[%d] = %d\n", next_v+1, C);
  }
}

int main() {
  cin >> N;
  vector< vector<ll> > G(N);
  G.resize(N);
  seen.resize(N, false);
  ans1.resize(N, 0);
  ans2.resize(N, 0);
  int k;
  int tmp;
  rep(i, N) {
    cin >> tmp >> k;
    rep(j, k) {
      int tmp;
      cin >> tmp;
      G[i].push_back(tmp-1);
    }
  }

  rep(i, N) {
    if (!seen[i]) {
      ans1[i] = ++C;
      dfs(G, i);
      ans2[i] = ++C;
    }
  }
  rep(i, N) {
    cout << i+1 << " " << ans1[i] << " " << ans2[i] << endl;
  }
  return 0;
}