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 <bits/stdc++.h>

using namespace std;

//ALDS1_11_B 深さ優先探索の問題
//再帰で解く

void dfs(vector<vector<int>> &G, int s, int &counter,vector<vector<int>> &res,vector<bool> &seen) {
	if (G[s].size() == 0) {
		counter++;
		res[s][1] = counter;
		counter++;
		res[s][2] = counter;
		return;
	}

	counter++;
	res[s][1] = counter;

	for (int i = 0; i < G[s].size(); i++) {
		if (seen[G[s][i]] == true) {
			continue;
		}
		seen[G[s][i]] = true;
		dfs(G, G[s][i],counter,res,seen);

	}
	counter++;
	res[s][2] = counter;
}

int main() {

	int n;
	cin >> n;
	vector < vector<int>> G(n + 1);

	//グラフ隣接リスト読み込み
	int a, b, c;
	for (int i = 1; i <= n; i++) {
		cin >> a >> b;
		for (int j = 0; j < b; j++) {
			cin >> c;
			G[a].push_back(c);
		}
	}

	vector<vector<int>> res(n+1,vector<int> (3));
	for (int i = 1; i <= n; i++) {
		res[i][0] = i;
	}
	
	int aa = 0;
	vector<bool> seen(n + 1,false);
	for (int i = 1; i<= n; i++) {
		if (seen[i]) { continue; }
		seen[i] = true;
		dfs(G, i, aa, res, seen);
	}

	for (int i = 1; i <= n; i++) {
		cout << res[i][0] << " " << res[i][1] << " " << res[i][2] << endl;
	}

	return 0;

}

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

#define WHITE 0
#define GRAY 1
#define BLACK 2

int G[101][101];
int color[101];
int n;
int d[101], f[101], t;

void search_loop(int i)
{
	int next;
	d[i] = ++t;
	color[i] = GRAY;

	for(next = 1; next <= n; next++){
		if(i == next && G[i][i] > 0) break;
		if(G[i][next] > 0 && color[next] == WHITE){
			search_loop(next);
		}
	}
	f[i] = ++t;
	color[i] = BLACK;

	return;
}

void dfs()
{
	int i;
	for(i = 1; i <= n; i++) color[i] = WHITE;  // initialize.

	t = 0;
	for(i = 1; i <= n; i++){
		if(color[i] == WHITE) search_loop(i);
	}
	for(i = 1; i <= n; i++){
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return ;
}

int main()
{
	int i, j, k, e;
	cin >> n;
	for(i = 1; i <= n; i++){
		for(j = 1; j <= n; j++){
			G[i][j] = 0;
		}
	}
	do{
		cin >> i >> e;
		for(j = 1; j <= e; j++){
			cin >> k;
			G[i][k] = 1;
		}
	}while(i < n);

	dfs();

	cin >> n;

	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
const int MAXN = 1000;
int n;
int d[MAXN];
int f[MAXN];
int t;
void solve(int current,vector<vector<int> > &g){
  if(d[current] > 0)return;
  t++;
  d[current] = t;
  
  for(int next:g[current]){
    solve(next,g);
  }
  t++;
  
  f[current] = t;
}

int main(){
  cin >> n;
  vector<vector<int> > g(n+1);
  for(int i = 1;i <= n;i++){
    int u,k;
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      int v;
      cin >> v;
      g[i].push_back(v);
    }
  }
  for(int i = 1;i <= n;i++){
    solve(i,g);
  }
  for(int i = 1;i <= n;i++){
    cout << i << ' ' << d[i] << ' ' << f[i] << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/
vector<int> data[100];
pair<int, int> finds[100];

int dfs(int foo, int timer)
{
    //foo is node number
    if(finds[foo].first!=-1) return timer; 
    finds[foo].first = ++timer;
    int result = timer;
    if (data[foo].size() != 0)
    {
        rep(i,data[foo].size())
        {
            result = dfs(data[foo][i], result);
        }
    }
    finds[foo].second= ++result;
    return result;
}

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        int temp;
        cin >> temp;
        cin >> temp;
        rep(j, temp)
        {
            int foo;
            cin >> foo;
            data[i].push_back(foo - 1);
        }
    }
    rep(i,100){
        finds[i].first=-1;
    }
    finds[0].second = dfs(0, 0);
    rep(i, n)
    {
        cout << i + 1 << " " << finds[i].first << " " << finds[i].second << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int k[101]={0},v[101][101]={0};
int d[101]={0},f[101]={0};
int cur=0;
void dfs(int id)
{
	if(d[id]!=0)
	{
		return;
	}
	cur++;
	if(d[id]==0)
	{
		d[id]=cur;
	}
	for(int i=0;i<k[id];i++)
	{
		dfs(v[id][i]);
	}
	cur++;
	f[id]=cur;
	return;
}
int main(void)
{
	int n=0,u=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&u);
		scanf("%d",&k[u]);
		for(int j=0;j<k[u];j++)
		{
			scanf("%d",&v[u][j]);
		}
	}
	for(int i=1;i<n;i++)
	{
		if(d[i]==0)
		{
			dfs(i);
		}
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d %d %d\n",i,d[i],f[i]);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

vector<int>visited;
vector<int>d,f;
int cnt;

void dfs(int v,vector<vector<int>> &g){
  if(!visited[v])visited[v]=1,d[v]=++cnt;
  for(auto x:g[v]){
    if(visited[x]==0){
      dfs(x,g);
    }
  }
  visited[v]=2;
  f[v]=++cnt;
}

void solve(){
  int n;
  cin>>n;
  cnt=0;
  visited.resize(n);
  d.resize(n);f.resize(n);
  vector<vector<int>>g(n);
  rep(i,n){
    int u;
    cin>>u;
    u--;
    int k;
    cin>>k;
    int v;
    rep(j,k){
      cin>>v;
      v--;
      g[u].pb(v);
    }
  }
  rep(i,n){
    if(!visited[i])dfs(i,g);
  }
  rep(i,n){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<"\n";
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}