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

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;
int f_stamp[103];
int e_stamp[103];
vector<vector<int> > edge;
int t;
void dfs(int v){
	REP(i,edge[v].size()){
		if(not f_stamp[edge[v][i]]){
			f_stamp[edge[v][i]] = ++t;
			dfs(edge[v][i]);
		}
	}
	e_stamp[v] = ++t;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	cin>>n;
	edge.resize(n,vector<int>());
	REP(i,n){
		int v;cin>>v;v--;int t;cin>>t;
		while(t--){
			int u;cin>>u;u--;
			edge[v].push_back(u);
		}
	}
	REP(i,n){
		if(not f_stamp[i]){
			f_stamp[i] = ++t;
			dfs(i);
		}
	}
	REP(i,n){
		cout << i+1 << ' ' << f_stamp[i] << ' ' << e_stamp[i] << endl;
	}
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <string>
#include <queue>

using namespace std;

int d[101];
int f[101];
bool isUsed[101];
int count = 0;

void dfs(vector< vector<int> >& G, int vertex);
void calclation();

int main()
{
	calclation();
	return(0);
}

void dfs(vector< vector<int> >& G, int vertex)
{
	d[vertex] = ++count;
	for (int i = 0; i < G[vertex].size(); ++i)
	{
		if (G[vertex][i] == 1 && isUsed[i] == false)
		{
			isUsed[i] = true;
			dfs(G, i);
		}
	}
	f[vertex] = ++count;
}

void calclation()
{
		int n;
	cin >> n;

	vector< vector<int> > G(n, vector<int>(n));
	for (int i = 0; i < n; ++i)
	{
		int h, k;
		cin >> h >> k;
		--h;
		for (int j = 0; j < k; ++j)
		{
			int v;
			cin >> v;
			--v;
			G[h][v] = 1;
		}
	}
	for (int i = 0; i < 101; ++i)
	{
		isUsed[i] = false;
	}
	for (int i = 0; i < n; ++i)
	{
		if (isUsed[i] == false)
		{
			isUsed[i] = true;
			dfs(G, i);
		}
	}
	for (int i = 0; i < n; ++i)
	{
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}