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 <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int c;
vector<int> E[SIZE];
int d[SIZE],f[SIZE]; //init:0

void dfs(int v){
  c++;
  d[v]=c;
  for(int to : E[v]) if(d[to] == 0){
    dfs(to);
  }
  c++;
  f[v] = c;
}

int n;

int main(){
  cin >> n;
  rep(i,0,n){
    int v,k;
    cin >> v >> k;
    rep(i,0,k){
      int u;
      cin >> u;
      //E[u].push_back(v);
      E[v].push_back(u);
    }
  }

  rep(i,0,n){
    if(d[i+1] ==0) dfs(i+1);
  };

  rep(i,0,n){
    cout << i+1 << " " <<  d[i+1] << " " << f[i+1] << endl;
  }

  return 0;
}

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

int main(){
  vector <vector<int> > path_field;
  int n;

  cin >> n; n++;
  path_field.resize(n);
  for(int i=1;i<n;i++){
    path_field[i].resize(n);
    for(int j=1;j<n;j++){
      path_field[i][j]=0;
    }
  }
  for(int i=1;i<n;i++){
    int _m,m;

    cin >> _m >> m;
    for(int j=0;j<m;j++){
      int to;
      
      cin >> to;
      path_field[i][to]=1;
    }
  }

  vector <tuple<int,int> > ans;
  deque <int> stk;
  int sarched_point,sum=0;

  ans.resize(n);
  for(int i=1;i<n;i++){
    ans[i]=make_tuple(0,0);
  }
  for(int i_=1;i_<n;i_++){
    if(get<0>(ans[i_])==0){
      stk.push_back(i_);
      if(sum!=0) sum++;
    }
  
    while(!stk.empty()){
      sarched_point = stk.back();
      sum++;

      if(get<0>(ans[sarched_point])==0){
        get<0>(ans[sarched_point])=sum;
      }
      for(int i=1;i<n;i++){
        if((path_field[sarched_point][i]==1)&&(get<0>(ans[i])==0)){
          stk.push_back(i);
       	  break;
        }else if(i==(n-1)){
          get<1>(ans[sarched_point])=sum+1;
          stk.pop_back();
        }
      }
    }
  }

  for(int i=1;i<n;i++){
    cout << i << " " << get<0>(ans[i]) << " " << get<1>(ans[i]) << endl;
  }
}

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

vector<int> *a;
bool *check;
int *d,*f;

int dfs(int u, int time){
    int i, v;
    check[u] = true;
    d[u] = time;
    time++;
    for(i=0;i<a[u].size();i++){
        v = a[u][i];
        if(!check[v])time = dfs(v,time);
    }
    f[u] = time;
    time++;
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    check = (bool *)malloc(sizeof(bool)*(n+1));
    d = (int *)malloc(sizeof(int)*(n+1));
    f = (int *)malloc(sizeof(int)*(n+1));
    for(i=0;i<=n;i++)check[i] = false;
    a = (vector<int> *)malloc(sizeof(vector<int>)*(n+1));

    for(i=1;i<=n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            a[u].push_back(v);
        }
    }

    int time = 1;
    for(i=1;i<=n;i++){
        if(!check[i])
        time = dfs(i,time);
    }

    for(i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],f[i]);

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD (int) 1e9+7

vector<int> E[200];
int d[200]={}, f[200]={};

int func(int pos, int time){
    if(d[pos]>0){
        return time;
    }
    d[pos] = time;
    time++;
    for (int to : E[pos]){
        time = func(to, time);
    }
    f[pos] = time;
    time++;
    return time;
}

int main(){
    int n;
    cin >> n;
    rep(i, n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            E[u].push_back(v);
        }
    }
    int time = 1;
    for (int i = 1; i <= n; i++){
        if(d[i]==0){
            time = func(i, time);
        }
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    // printf("%d\n", N);
    return 0;
}

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

int m[101][101];
int visit[101];
int d[101];
int f[101];
int n, t;

void dfs(int u){
  visit[u] = 1;
  d[u] = t;
  t++;
  
  for(int i = 0; i < n; ++i){
    if(m[u][i] == 1 && visit[i] == 0){
      dfs(i);
    }
  }

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

main()
{
  int u, k, v;
  t = 1;

  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;
    }
  }

  for(int i = 0; i < n; ++i){
    if(visit[i]==0){
      dfs(i);
    }
  }

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

  return (0);
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
int n;
int v,k,tm;
vector<int> graph[105];
int star[105],tend[105];//记录结束和开始
int vis[105];//纪律顶点是否被访问
void dfs(int u,int& deep)
{
    vis[u]=1;//表示该点已经被访问
    star[u]=deep++;
    sort(graph[u].begin(),graph[u].end());//排序
    for(int i:graph[u])
    {
        if(vis[i]==0){dfs(i,deep);}
    }
    tend[u]=deep++;
    return ;
}
int main()
{
    clr(star,0);clr(tend,0);
    clr(vis,0);
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>v>>k;
        while(k--)
        {
            cin>>tm;
            graph[v].push_back(tm);//连接的点
        }
    }
    int deep=1;
    dfs(1,deep);
    for(int i=1;i<=n;++i)
    {
        cout<<i<<" "<<star[i]<<" "<<tend[i]<<endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <stack>
#include <cstdio>
using namespace std;
static const int MAX = 100;

int adj[MAX][MAX] = {0};
int n;

enum Color {
  WHITE,
  GRAY,
  BLACK,
};

struct node {
  Color color;
  int begin;
  int end;
};

node nodes[MAX];

void paint(int id, Color c) {
  static int time = 1;
  nodes[id].color = c;
  if (c == GRAY)
    nodes[id].begin = time;
  else if (c == BLACK)
    nodes[id].end = time;
  time++;
}

int next(int id) {
  for (int i = 0; i < n; i++) {
    if (adj[id][i] == 1 && nodes[i].color == WHITE) {
      return i;
    }
  }
  return -1;
}

void visit(int id) {
  stack<int> S;
  S.push(id);
  paint(id, GRAY);

  while (!S.empty()) {
    int u = S.top();
    int v = next(u);
    if (v > -1) {
      paint(v, GRAY);
      S.push(v);
    } else {
      S.pop();
      paint(u, BLACK);
    }
  }
}

void dfs() {
  for (int i = 0; i < n; i++) {
    nodes[i].color = WHITE;
  }
  for (int i = 0; i < n; i++) {
    if (nodes[i].color == WHITE)
      visit(i);
  }
}

void printNode(int i) {
  printf("%d %d %d\n", i+1, nodes[i].begin, nodes[i].end);
}

int main() {
  cin >> n;
  int id, nn, x;
  for (int i = 0; i < n; i++) {
    cin >> id >> nn;
    id--; // 0-based
    for (int j = 0; j < nn; j++) {
      cin >> x;
      x--; // 0-based
      adj[id][x] = 1;
    }
  }

  dfs();

  for (int i = 0; i < n; i++) {
    printNode(i);
  }
}