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<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, tt;
int M[N][N], color[N], d[N], f[N], nt[N]; 

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) {
			if(color[v] == WHITE) {
			   color[v] = GRAY;
			   d[v] = ++tt;
			   S.push(v); 	
			}
		} else {
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


void dfs() {
	for(int i = 0; i < n; i++) {
	     color[i] = WHITE;
	}
	tt = 0;	
	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 n, k , u, v;
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}
	cin >> u >> k;
	u--;
	for(int i = 0; i < k; i++) {
	    cin >> v;
	    v--;
		M[u][v] = 1; 
	}
	dfs();
	return 0;
}

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

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int G[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(G[dst][cur]==1&&c[dst]==0){
			dfs(dst);
			t += 1;
		}
	} 
	mytime2[cur]=t;
}


int main()
{
	vector<int> v[110];
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int tmp;
			cin>>tmp;
			v[u].push_back(tmp);
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			G[i][j]=0;
		}
	}
	for(int i=1;i<n+1;i++){
		for(int j=0;j<v[i].size();j++){
			G[i-1][v[i][j]-1]=1; //
		}
	}
	for(int i=0;i<n;++i){
		dfs(i);
		cout<<(i+1)<<' '<<mytime1[i]<<" "<<mytime2[i] <<endl;
}
}

C++: #include<bits/stdc++.h>
#define N 105
using namespace std;
int n,u,k,v,e[N][N],cnt;
int ans1[N],ans2[N];
bool used[N];

void dfs(int x){
  if(used[x])return;
  used[x]=true;
  ans1[x]=cnt++;
  for(int i=0;i<n;i++)
    if(e[x][i])dfs(i);
  ans2[x]=cnt++;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++)
      cin>>v,e[u-1][v-1]=1;
  }
  cnt=1;
  for(int i=0;i<n;i++){
    if(!used[i])dfs(i);
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<' '<<ans1[i]<<' '<<ans2[i]<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <utility>
#define N 	100

using namespace std;

int T[N+1][N+1];
pair<int , int> M[N+1];
int t = 0;

void init(){
	for (int i = 0; i < 100; ++i)
	{
		M[i].first = 0;
		M[i].second = 0;
		for (int j = 0; j < 100; ++j)
		{
			T[i][j] = 0;
		}
	}
}

void DispTable(int n){
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			cout << T[i][j];
			if(j!=n) cout << " ";
		}
		cout << endl;
	}
}

void DispM(int n){
	for (int i = 1; i<=n; i++)
	{
		cout << i << " " << M[i].first << " " << M[i].second << endl;
	}
}

void dfs(int cur,int n){
	t++;
	M[cur].first = t;
	// cerr << "visiting " << cur << " " << t << endl;
	for (int i = 1; i <= n; ++i)
	{
		if(T[cur][i] == 1 && M[i].first == 0) dfs(i,n);
	}
	t++;
	M[cur].second = t;
}

int main(){
	int n;
	cin >> n;
	init();
	for (int i = 0; i < n; ++i)
	{
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; ++j)
		{
			int v;
			cin >> v;
			T[u][v] = 1;	
		}
	}
	// DispTable(n);
	dfs(1,n);
	for (int i = 2; i <= n; ++i)
	{
		if(M[i].first==0) dfs(i,n);
	}
	DispM(n);
	return 0;
}

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


void solve(int);

typedef struct{
  int k;
  vector<int> ls;
  int f,d;
}node_t;

node_t node[101];
int t=0;

int main(){
  int n;
  int u;

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> u; 
    cin >> node[u].k;
    node[u].ls.resize(node[u].k);
    node[u].d = node[u].f = -1;
    for(int j=0; j<node[u].k; j++){
      cin >> node[u].ls[j];
    }
    sort(node[u].ls.begin() , node[u].ls.end());
  }
 
  solve(1);

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

  return 0;
}



void solve(int id){
  t++;
  if(node[id].d == -1)node[id].d = t;
  else {t--;return;}

  for(int i=0; i<node[id].k; i++){
    solve(node[id].ls[i]);
  }
  node[id].f = ++t;
}

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, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

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) {
            if (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;
        nt[i] = 0;
    }
    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();

    return 0;
}