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<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


int visitTime = 1;
int d[101],f[101],n[101],v[101][101],id;


void dfs(int cur) { // cur????¨????
	d[cur] = visitTime;// cur????¨??????????????¨????
	visitTime += 1;
	rep(i,n[cur]){ // ??¨????????? v[cur][i] ????????????
		if(d[v[cur][i]]==0){ // v[cur][i] ???????¨??????????
			dfs(v[cur][i]);
		}
	}
	f[cur] = visitTime;// cur ????¨????????????????????¨????
	visitTime += 1;
	// ??¢??°??????????????§???????????? (?????¢??°)
}

int main(void){
	int N;
	cin>>N;
	rep(i,N){
		cin>>id;
		cin>>n[id];
		rep(j,n[id])cin>>v[id][j];
	}
	dfs(1);
	reg(i,1,N)cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}

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

const int MAX_N = 100;
vector<int> G[MAX_N];
int d[MAX_N], f[MAX_N];
bool used[MAX_N];

int stamp;

void dfs(const int v) {
    d[v] = stamp++;
    used[v] = true;
    for(int i = 0; i < (int)G[v].size(); i++) {
        int u = G[v][i];
        if(used[u] == false) dfs(u);
    }
    f[v] = stamp++;
}

int main() {
    int N; cin >> N;
    for(int i = 0; i < N; i++) {
        int u, k; cin >> u >> k; u--;
        while(k--) {
            int v; cin >> v; v--;
            G[u].push_back(v);
        }
        sort(G[u].begin(), G[u].end());
    }

    fill(used, used + N, false);
    stamp = 1;
    for(int i = 0; i < N; i++) {
        dfs(i);
    }

    for(int i = 0; i < N; i++) {
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

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

vector<int> G[100];
pair<int, int> T[100];
const int Inf = 10000*100000+100;
int timer = 1;

int main() {
  void dfs(int cur);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int u, k;
    cin >> u >> k;
    for (int l = 0; l < k; l++) {
      int v;
      cin >> v;
      G[i].push_back(v - 1);
    }
    T[i] = make_pair(Inf, Inf);
  }
  for (int i = 0; i < n; i++) {
    if (T[i].first == Inf) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; i++)
  {
    cout << i + 1 << " " << T[i].first << " " << T[i].second << endl;
  }
}

void dfs(int cur) { // cur を訪問
  // cur の訪問時刻を記録
  T[cur].first = timer;
  timer += 1;
  // 動作確認用表示
  for (int dst : G[cur]) { // 全ての節点 dst について
    if (T[dst].first == Inf)
    { // cur から dst に辺があり，dst を未訪問なら
      dfs(dst);
    }
  }
  T[cur].second = timer;
  timer += 1;
}

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

int n;
bool G[110][110];
int d[110], f[110], timer;
bool seen[110];

void dfs(int now){
    d[now] = timer;

    seen[now] = true;

    for(int to=1; to<=n; ++to){
        if(G[now][to] == true && seen[to] == false){
            ++timer;
            dfs(to);
        }
    }

    ++timer;
    f[now] = timer;

}

int main(){
    cin >> 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;
            G[u][v] = true;
        }
    }

    timer = 0;
    for(int i=1; i<=n; ++i){
        if(seen[i] == false){
            ++timer;
            dfs(i);
        }
    }

    for(int i=1; i<=n; ++i){
        printf("%d %d %d\n", i, d[i], f[i]);
    }
}

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

int t=1;
int n;
int d[101],f[101];
int v[101];
vector<int> edges[101];

void dfs(int cur)
{
    if(d[cur]==-1)
    {
        d[cur]=t;
        v[cur]=1;
        t+=1;
    }
    int dst;
    for(dst=1;dst<=n;dst++)
    {
        int flag=0;
        for(int i=0;i<edges[cur].size();i++)
        {
            if(edges[cur][i]==dst)
				{
					flag=1;
					break;
				}
        }
        if(v[dst]==-1&&flag)
		  dfs(dst);
    }
    if(f[cur]==-1)
    {
        f[cur]=t;
        t+=1;
    }
}

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int u,k,y;
		cin >> u >> k;
		for(int j=0;j<k;j++)
        {
            cin >> y;
            edges[u].push_back(y);
        }
	}
	for(int i=1;i<=n;i++)
	{
        d[i]=-1;
        f[i]=-1;
        v[i]=-1;
    }
	for(int dst=1;dst<=n;dst++)
        dfs(dst);
	for(int i=1;i<=n;i++)
	   cout << i << ' ' << d[i] <<  ' ' <<  f[i] <<  endl;
}

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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
vi d, f;
vvi G;
int t = 0;

void dfs(int n)
{
    t++;
    d[n] = t;
    for(int i : G[n]) if(d[i] == 0) dfs(i);
    t++;
    f[n] = t;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> n;
    G.resize(n+1);
    d.resize(n+1, 0);
    f.resize(n+1, 0);
    REP(i, n)
    {
        int u, k; cin >> u >> k;
        REP(j, k)
        {
            int v; cin >> v;
            G[u].pb(v);
        }
    }

    REPS(i, n)
    {
        if(d[i] == 0) dfs(i);
    }

    REPS(i, n) cout << i << " " << d[i] << " " << f[i] << endl;
}