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 <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class DFS
{
public:
  int n;
  int solve();
  int dfs( int v, int t, vector<vector<int>>& adj, vector<int>& d, vector<int>& f );
};

int DFS::dfs( int v, int t, vector<vector<int>>& adj, vector<int>& d, vector<int>& f )
{
  if ( d[v] )
    return t;
  else
    d[v] = t++;

  for ( auto i = 1; i <= n; ++i )
    if ( adj[v][i] )
      t = dfs( i, t, adj, d, f );

  f[v] = t;

  return ++t;
}

int DFS::solve()
{
  cin >> n;

  vector<vector<int>> adj(n+1, vector<int>(n+1, 0));
  vector<int> d(n+1,0);
  vector<int> f(n+1,0);

  for ( auto i = 0; i < n; ++i )
    {
      int x, k;
      cin >> x;
      cin >> k;
      for ( auto j = 0; j < k; ++j )
        {
          int y;
          cin >> y;
          adj[x][y] = 1;
        }
    }

  int t = 1;
  
  for ( auto i = 1; i <= n; ++i )
    t = dfs( i, t, adj, d, f );

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

int main()
{
  DFS d;

  d.solve();

  return 0;
}

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

void DFS(vector<vector<int> > A, vector<int> &d, vector<int> &f, vector<int> &visit, int &t, int v){
	
	visit[v] = 1;
	d[v] = t++;

	for(int i=0;i<A[v].size();i++)
		if((A[v][i] == 1) && (visit[i] == 0))
			DFS(A, d, f, visit, t, i);

	f[v] = t++;
}

int main(){
	int n, u, k, t=1;
	vector<vector<int> > A;
	vector<int> d, f, visit;

	cin>>n;
	A.resize(n);
	d.resize(n);
	f.resize(n);
	for(int i=0;i<n;i++){
		A[i].resize(n);
		visit.push_back(0);
	}

	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			A[i][j] = 0;

	for(int i=0;i<n;i++){
		cin>>u>>k;
		int v;
		
		for(int j=0;j<k;j++){
			cin>>v;
			A[u-1][v-1] = 1;
		}
	}

	DFS(A, d, f, visit, t, 0);
	for(int i=0;i<n;i++)
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;

	return 0;
}

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

int r[101][101];
int d[101], f[101], num, visit[101], p=0;

void dfs(int n){
    if(!visit[n]){
        visit[n]++;
        d[n] = ++p;
        for(int i=1; i<num+1; i++)
            if(r[n][i]) dfs(i);
        f[n] = ++p;
    }
}

int main(void){
    int u, k, v;
    cin >> num;
    for(int i=0; i<num; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v;
            r[u][v]++;
        }
    }
    for(int i=1; i<num+1; i++){
        if(!visit[i]) dfs(i);
    }
    for(int i=1; i<num+1; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
}

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

using namespace std;

int N,k[1000];
int v[1000][1000];
int found[1000] = {0},ended[1000] = {0};
int keep;
int checking=0;

void dfs(int cur);

int main() {
	cin >> N;
	for(int i=1;i<N+1;i++) {
		cin >> keep >> k[i];
		for(int j=1;j<k[i]+1;j++) {
			cin >> v[i][j];

		}
	}
	dfs(1);
	
	for(int i=1;i<N+1;i++) {
		cout << i << " " << found[i] << " " << ended[i] << endl;
	}
	

}

void dfs(int cur) {
	
	if(!found[cur]) {
		checking++;
		//cerr << "visiting: " << cur << " " << "time: " << checking << endl;
		found[cur] = checking;
	}
	for(int dst=1;dst<N+1;dst++) {
		bool flag = false;
		for(int i=1;i<k[cur]+1;i++) {
			if(v[cur][i] == dst) flag = true;
		}
		if(flag) dfs(dst);
	}
	if(!ended[cur]) {
		checking++;
		//cerr << "ended: " << cur << " " << "time: " << checking << endl;
		ended[cur] = checking;
	}
}

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

int main(){
    unsigned long n;
    std::cin >> n;

    std::vector<std::vector<unsigned long>> edges(n);
    for(auto&& i : edges){
        unsigned long u;
        std::cin >> u;
        unsigned long k;
        std::cin >> k;
        i = std::vector<unsigned long>(k);
        for(auto&& j : i){
            std::cin >> j;
            --j;
        }
    }

    std::vector<unsigned long> d(n), f(n);

    [dfs_impl = [&edges, &d, &f](auto func, unsigned long now, unsigned long& t) -> void {
        d[now] = ++t;
        for(const auto& i : edges[now])if(!d[i])func(func, i, t);
        f[now] = ++t;
    }, &n, &d]{
        unsigned long t{0};
        for(unsigned long i{0}; i < n; ++i)if(!d[i])dfs_impl(dfs_impl, i, t);
    }();

    for(unsigned long i{0}; i < n; ++i)std::cout << i + 1 << " " << d[i] << " " << f[i] << std::endl;

    return 0;
}