Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	dfs(&g, &d, &f, 1, 1)

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

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

int n, u, k, v;
int d[101], f[101];
pair<int, vector<int>> G[101];

int ti = 1;

void dfs(int id) {
	d[id] = ti ++;

	vector<int>& adj = G[id].second;
	for (int i=0, l=adj.size(); i<l; ++i) {
		if ( ! d[adj[i]]) {
			dfs(adj[i]);
		}
	}
	f[id] = ti ++;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> u >> k;
		G[u].first = u;
		while (k --) {
			cin >> v;
			G[u].second.push_back(v);
		}
	}
	dfs(1);

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

C++: #include <cstdio>
#include <vector>
using namespace std;
int Begin;
int step=1;
int root[105]={0};
typedef struct{
	int id;
	vector<int>next;
	int num;
	int find;
	int finish;
}inf;
void input(int cases,inf table[]){
	for(int i=0;i<cases;i++){
		int id;
		scanf("%d",&id);
		table[id].id=id;
		scanf("%d",&table[id].num);
		for(int i=0;i<table[id].num;i++){
			int next;
			scanf("%d",&next);
			table[id].next.push_back(next);
			root[next]=1;
		}
		table[id].find=-1;
		table[id].finish=-1;
	}
}
void dfs(inf table[],int now){
	if(table[now].num==0){
		table[now].find=step;
		step++;
		table[now].finish=step;
		step++;
		return;
	}else{
		if(table[now].find==-1){
			table[now].find=step;
		}
		step++;
		for(int i=0;i<table[now].num;i++){
			if(table[table[now].next[i]].find==-1){
				dfs(table,table[now].next[i]);				
			}
		}
		table[now].finish=step;
		step++;
	}
}
void find_begin(int cases){
	for(int i=1;i<=cases;i++){
		if(root[i]==0){
			Begin=i;
			break;
		}
	}
}
int main(){
	int cases;
	scanf("%d",&cases);
	inf table[105];
	input(cases,table);
	find_begin(cases);
	dfs(table,Begin);
	for(int i=1;i<=cases;i++){
		printf("%d %d %d\n",i,table[i].find,table[i].finish);
	}
}

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

void DFS(vector<vector<int> >& G,
        vector<pair<int, int> >& rec, int i) {
    if (rec[i].first != -1) return;
    static int t = 1;
    rec[i].first = t++;
    for (int j = 1; j <= G[i].size(); j++) {
        if (G[i][j]) DFS(G, rec, j);
    }
    rec[i].second = t++;
}

int main(){
    int n;
    cin >> n;
    vector<vector<int> > G(n + 1, vector<int>(n + 1, 0));
    for (int i = 1; i <= n; i++) {
        int num, k;
        cin >> num >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            G[i][v] = 1;
        }
    }
    vector<pair<int, int> > record(n + 1, make_pair(-1, -1));
    int t = 1;
    for (int i = 1; i <= n; i++) {
        DFS(G, record, i);
    }

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

    return 0;
}

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

using namespace std;

#define MAX 110
int num;
int matrix[MAX][MAX];
int dst[MAX];
int counter = 0;
int D[MAX];
int F[MAX];

void input(){
    cin >> num;
    for(int i=0;i<MAX;i++){
        dst[i] = -1;
        for(int j=0;j<MAX;j++){
            matrix[i][j] = 0;
        }
    }
    for(int i=1;i<=num;i++){
        int v; cin >> v;
        int tmp; cin >>tmp;
        for(int j=0;j<tmp;j++){
            int vi; cin >> vi;
            matrix[v-1][vi-1] = 1;
        }
    }
}

void dfs(int cur){
    counter++;
    D[cur] = counter;
    for(int i=0; i< num;i++){
        if(matrix[cur][i] == 1 && D[i]== 0)
            dfs(i);
    }
    F[cur] = counter+1;
    counter++;
    return;
}

int main(){
    input();
    for(int i=0;i<MAX;i++){
        D[i] = 0;
        F[i] = 0;
    }
    dfs(0);
    for(int i=0;i<num;i++){
        cout << i+1 << " " << D[i] << " " << F[i] << endl;
    }
}

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