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 <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

set<int> to[101];
vector<int> from[101];
vector<int> d(101);
vector<int> f(101);

int dfs(int n, int t){
    if(d[n] != -1) return t-1;
    d[n] = t;
    for(auto it = to[n].begin(); it != to[n].end(); it++){
        t = dfs((*it),t+1);
    }
    t++;
    f[n] = t;
    return t;
}

int main(){
    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 v;
            cin >> v;
            to[u].insert(v);
            from[v].push_back(u);
        }
        d[u] = -1;
        f[u] = -1;
    }
    
    int t = dfs(1,1);
    for(int i = 1; i <= n; i++){
        if(d[i] == -1){
            t = dfs(i,t+1);
        }
    }

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

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rp(i,j) for(long long i=0;i<j;i++)
#define rep(i,j,k) for(long long i=j;i<k;i++)
#define mod 1000000007
#define NIL -1
#define white 0
#define gray 1
#define black 2
typedef long long ll;
int n,tt=0,d[100],f[100];
int a[100][100]={0};
int nt[100]={1};
int color[100]={0};
void dfs_visit(int u){
    color[u]=gray;
    d[u]=++tt;
    rp(v,n){
        if(a[u][v]==0)continue;
        if(color[v]==white){
            dfs_visit(v);
        }
    }
    color[u]=black;
    f[u]=++tt;
}
void dfs(){
    rp(u,n){
        if(color[u]==white)dfs_visit(u);
    }
    rp(u,n){
        cout<<u+1<<" "<<d[u]<<" "<<f[u]<<endl; 
    }
}
int main(){
    int u,k,v;
    cin>>n;
    rp(i,n){
        cin>>u>>k;
        u--;
        rp(j,k){
            cin>>v;
            v--;
            a[u][v]=1;
        }
    }
    dfs();
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
bool g[110][110];
int d[110];
int f[110];

void dfs(int s)
{
	stack<int> stk;
	d[s] = 0;
	stk.push(s);
	int current = 0;
	while (!stk.empty()) {
		int u = stk.top();
		int flag = 0;
		for (int j = 1; j <= n; j++) {
			if (g[u][j] && d[j] == -1) {
				flag = 1;
				stk.push(j);
				d[j] = ++current;
				break;
			}
		}

		if (flag == 0) {
			f[u] = ++current;
			stk.pop();
		}

	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		int u, k, v;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			g[u][v] = true;
		}
	}

	for (int i = 1; i <= n; i++) {
		d[i] = -1;
		f[i] = -1;
	}

	dfs(1);

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

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include<stack>
#include <algorithm>
using namespace std;
#define max 101
#define WHITE 0
#define BLACK 1
#define GRAY -1
int color[max],d[max],f[max];
int t,varry[max][max];
stack<int> s;
int next(int u){
  int nv=-1;
  for(int i=0;i<varry[u][0];i++){
    if(color[varry[u][i+1]]==WHITE){
      nv=varry[u][i+1];
      break;
    }
  }
  
  return nv;
}
void visit(int r){
  int u,v;
  s.push(r);
  d[r]=++t;
  while(!s.empty()){
    u=s.top();
    v=next(u);
    if(v!=-1){
      if(color[v]==WHITE){
	s.push(v);
	color[v]=GRAY;
	d[v]=++t;
      }
    }
    else{
      s.pop();
      color[u]=BLACK;
      f[u]=++t;
      
    }
  }
}
void dfs(int u){
  for(int i=1;i<=u;i++)
    if(color[i]==WHITE)visit(i);
}
int main(){
  int n,u;
  cin>>n;
  for(int k=0;k<n;k++){
    cin>>u;
    cin>>varry[u][0];
    for(int i=0;i<varry[u][0];i++)
      cin>>varry[u][i+1];

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


  return 0;
}

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

void dfs(vector<vector<int>> g, bool seen[], int start, int d[], int f[], int &first)
{
    seen[start] = true;
    d[start] = first++;
    for (auto v : g[start])
    {
        if (seen[v])
        {
            continue;
        }
        dfs(g, seen, v, d, f, first);
    }
    f[start] = first++;
}

int main()
{
    int n;
    int first = 1;
    int last = 1;
    cin >> n;
    int d[n + 1], f[n + 1];
    bool seen[n + 1];
    vector<vector<int>> g(n + 1);
    for (int i = 1; i <= n; i++)
    {
        seen[i] = false;
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (!seen[i])
        {
            dfs(g, seen, i, d, f, first);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
}

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

int D[100];
int a[100][100];

int main() {
  for (int i = 0; i < 100; i++){
    for (int j = 0; j < 100; j++){
	  a[i][j] = 0;
	  }
	 }
	int n,u,k,v;
	cin >>n;
	for (int i = 0; i < n; i++) {
	  cin >> u >> k;
	  for (int j = 0; j < k; j++) {
	    cin >> v;
		a[u][v] = 1;
		}
	  }
queue<int> Q; //整数を管理するキューの定義
  for (int i = 1; i < n+1; i++){
   D[i] = -1;
   }
  int src = 1;
  Q.push(src);
  D[src] = 0; //出発点
  while (! Q.empty()) {
    int cur = Q.front(); //先頭要素を取り出す
	Q.pop();
	for (int dst = 1; dst <= n; dst++) {
    if((a[cur][dst] == 1 && D[dst] == -1)) { //curからdstに辺があり、dstが未訪問なら
	  D[dst] = D[cur] +1;
	  Q.push(dst);
	  }
	}
}

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

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

int n, t=1;
vector<int> d, f;
vector<vector<int>> graph;
vector<int> flg;
void dfs(int v){
    flg[v]=1;
    d[v]=t;
    t++;

    for(int i : graph[v]){
        if(!flg[i]) dfs(i);
    }

    f[v]=t;
    t++;
}

int main() {

    cin >> n;
    d.assign(n+1, 0);
    f.assign(n+1, 0);
    graph.assign(n+1, {});
    flg.assign(n+1, 0);
    int u, k, tmp;
    for(int i=1; i<=n; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> tmp;
            graph[i].push_back(tmp);
        }
    }
    
    for(int i=1; i<=n; i++){
        if(!flg[i]) dfs(i);
    }

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