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>
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 tim = 0;
vector<vector<int>> to;
vector<bool> reached;
vector<int> d;
vector<int> f;



void dfs(int point);

int main()
{
    int n;
    cin >> n;
    to.resize(n+1);
    for(int i = 1; i <= n; i++){
        int m;
        cin >> m;
        cin >> m;
        to[i].resize(m);
        for(int j = 0; j < m; j++){
            cin >> to[i][j];
        }
    }
    
    reached.resize(n+1);
    d.resize(n+1);
    f.resize(n+1);

    dfs(1);

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

    return 0;
}

void dfs(int point)
{
    tim++;
    reached[point] = true;
    d[point] = tim;
    for(int i = 0; i < to[point].size(); i++){
        if(!reached[to[point][i]]){
            dfs(to[point][i]);
        }
    }
    tim++;
    f[point] = tim;
}

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

const int N = 100;
const int white = 0;
const int gray = 1;
const int black = 2;

int n,M[N][N];
int color[N],d[N],f[N],tt;

//?????°dfs
void dfs_visit(int u){
    int v;
    color [u] = gray;
    d[u] = ++tt; //??????????¨????
    for ( v = 0; v < n ; ++v) {
        if (M[u][v] == 0)continue;
        if (color[v] == white){
            dfs_visit(v);
        }
    }
    color[u] = black;
    f[u] = ++tt; //?¨?????????????
}

void dfs(){
    int u;
    for (u = 0; u < n; ++u) {
        color[u] = white;
    }
    tt = 0;

    for (int u = 0; u < n ; ++u) {
        //????¨???????u????§??????¨????????±???????????¢?´¢
        if(color[u] == white) dfs_visit(u);
    }
    for (int u = 0; u < n ; ++u) {
        cout << u+1 << " " << d[u] << " " << f[u] << " " << endl;
    }
}

int main(){
    int u,v,k;
    M[N][N] = {0};
    cin >> n;
    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;

}

C++: #include<iostream>
#include<stack>
#define MAX 100
#define BLACK 2
#define WHITE 0
#define GRAY 1
using namespace std;

void dfsInit();
void dfs(int);
int next(int);

int n,A[MAX][MAX];
int color[MAX],d[MAX],f[MAX],nt[MAX];
int time1;
int main(){
  int i,j,u,v,k;
  cin >> n;
  for(i = 0; i < n; i++){
    for(j = 0; j< n; j++){
      A[i][j] = 0;
    }
  }
  for(i = 0; i < n; i++){
    cin >> u;
    cin >> k;
    u = u-1;
    for(j = 0; j < n; j++){
      cin >> v;
      v = v-1;
      A[u][v] = 1;
    }
  }
  dfsInit();
  return 0;
}

void dfsInit(){
  for(int i = 0; i < n; i++){
    color[i] = WHITE;
    nt[i] = 0;
  }
  time1 = 0;
  for(int u = 0; u < n; u++){
    if(color[u] == WHITE){
      dfs(u);
    }
  }
  for(int i = 0; i < n; i++){
    //printf("%d %d %d\n",i+1,d[i],f[i]);
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
}

int next(int u){
  int v;
  for(v = nt[u]; v < n; v++){
    nt[u] = v+1;
    if(0 < A[u][v]){
      return v;
    }
  }
  return -1;
}
void dfs(int u){
  for(int i = 0; i < n; i++){
    nt[i] = 0;
  }
  stack<int> S;
  S.push(u);
  color[u] = GRAY;
  d[u] = ++time1;
  while(!S.empty() ){
    int r = S.top();
    int v = next(u);
    if(v != -1){
      if(color[v] == WHITE){
        color[v] = GRAY;
        d[v] = ++time1;
        S.push(v);
      }
    }
    else{
      S.pop();
      color[r] = BLACK;
      f[r] = ++time1;
    }
  }
}

C++: #include <cstdio>
#include <vector>
using namespace std;
int n, d[101], f[101]; vector<int> v[101];
int dfs(int c, int x) {
  if(d[c] > 0) return x;
  d[c] = x++;
  for(int i = 0; i < v[c].size(); ++i) {
    x = dfs(v[c][i], x);
  }
  f[c] = x++;
  return x;
}
int main() {
  scanf("%d", &n);
  for(int i = 0, u, k; i < n; ++i) {
    scanf("%d %d", &u, &k);
    for(int j = 0, vj; j < k; ++j) {
      scanf("%d", &vj);
      v[u].push_back(vj);
    }
  }
  for(int i = 1, s = 1; i <= n; ++i) {
    s = dfs(i, s);
  }
  for(int id = 1; id <= n; ++id) {
    printf("%d %d %d\n", id, d[id], f[id]);
  }
}

C++: #include<iostream>
#include<algorithm>
#include<stack>
#define MAX 101
using namespace std;
int n,tim=0;
int A[MAX][MAX]={0};
int color[MAX]={0},d[MAX]={0},f[MAX]={0};
stack<int> Number_of_vertices;
int input(void){
    int start;
    cin >> n;
    for(int i=0;i<n;i++){
        int id,adj;
        cin >> id >> adj;
        if(i==0){
            start = id-1;
            Number_of_vertices.push(id-1);   
        }
        for(int j=0;j<adj;j++){
            int k;
            cin >> k;
            A[id-1][k-1] = 1;
        }
    }
    return start;
}
void depth_first_search(int id){
    tim++;
    if(color[id]!=1){
        color[id] = 1;
        d[id] = tim;
    }
    for(int i=0;i<n;i++){
        if(A[id][i]==1 && color[i]!=1){
            Number_of_vertices.push(i);
            depth_first_search(i); 
        }
    }
    tim++;
    f[Number_of_vertices.top()] = tim;
    Number_of_vertices.pop();
}
void check(void){
    for(int i=0;i<n;i++){
        if(color[i]==0){
            int start = i;
            Number_of_vertices.push(start);
            depth_first_search(start);
        }
    }
}
void print(void){
    for(int i=0;i<n;i++){
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}
int main(void){
    int start;
    start = input();
    depth_first_search(start);
    check();
    print();
    return 0;
}