Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

C++: #include <cstdio>
#include <cstring>

const int MAX = 100;
static int time = 0;
int adj[MAX][MAX];
int discover[MAX];
int finish[MAX];

void visit(int node, int n)
{
  if (finish[node] != 0)
    return;

  ++time;
  discover[node] = time;

  for (int i = 0; i < n; ++i)
  {
    if (adj[node][i] == 1 && node != i)
      visit(i, n);
  }

  ++time;
  finish[node] = time;
}

int main()
{
  std::memset(adj, 0, sizeof(adj));
  std::memset(discover, 0, sizeof(discover));
  std::memset(finish, 0, sizeof(finish));

  int n;
  scanf("%d", &n);

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

  for (int i = 0; i < n; ++i)
    visit(i, n);

  for (int i = 0; i < n; ++i)
    printf("%d %d %d\n", i + 1, discover[i], finish[i]);

  return 0;
}

C++: #include"iostream"
#include"vector"
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
class vertex
{
public:
  vector<int> next;
  int first;
  int second;
  int color;
  vertex()
  {
    this->color=WHITE;
  }
};
vector<vertex> V;
int Time;
void visit(int u)
{
  V[u].color=GRAY;
  V[u].first=++Time;
  for(int v=0;v<V[u].next.size();v++)
    {
      if(V[V[u].next[v]].color==WHITE)
        {
          visit(V[u].next[v]);
        }
    }
  V[u].color=BLACK;
  V[u].second=++Time;
}
void dfs()
{
  for(int u=1;u<V.size();u++)
    {
      V[u].color=WHITE;
    }
  Time=0;
  for(int u=1;u<V.size();u++)
    {
      if(V[u].color==WHITE)
        {
          visit(u);
        }
    }
}
int main()
{
  int n;
  cin>>n;
  for(int i=0;i<=n;i++)
    {
      vertex a;
      V.push_back(a);
    }
  for(int i=1;i<=n;i++)
    {
      int num;
      cin>>num;
      int k;
      cin>>k;
      for(int j=0;j<k;j++)
        {
          int next;
          cin>>next;
          V[num].next.push_back(next);
        }
    }
  dfs();
  for(int i=1;i<=n;i++)
    {
      cout<<i<<" "<<V[i].first<<" "<<V[i].second<<endl;
    }
  return 0;
}

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

//AOJ Depth First Search
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja
using Graph = vector<vector<int>>;
vector<bool> seen;
vector<int> first_order;
vector<int> last_order;

void dfs(const Graph &G,int v,int& first_ptr){
    seen[v] = true;

    first_order[v] = first_ptr++;
    for(auto next_v: G[v]){
        if(seen[next_v]) continue;
        dfs(G,next_v,first_ptr);
    }
    last_order[v] = first_ptr++;
}
int main() {
    int v;
    cin >> v ;
    Graph G(v);

    rep(i,v){
        int u,k;
        cin >> u >> k;
        rep(j,k){
            int vi;
            cin >> vi;
            G[u-1].push_back(vi-1);
        }
    }

    seen.assign(v,false);
    first_order.resize(v);
    last_order.resize(v);
    int first_ptr = 1;
    rep(vi,v){
        if(seen[vi])continue;
        dfs(G, vi, first_ptr);
    }
    rep(i,v){
        cout << i+1 << " " << first_order[i] << " " << last_order[i] << endl;
    }
}

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

using namespace std;

const int edge = 1;
const int no_edge = 0;
const int no_time = -1;
const int no_label = -1;


// return finished time
int depth_search(
  int started_label,
  int current_time,
  vector<vector<int>> matrices_graph,
  vector<int>& discovered_times,
  vector<int>& finished_times
) {
  stack<int> visited_stack;
  int vertex_num = matrices_graph.size();
  visited_stack.push(started_label);
  discovered_times[started_label -1] = ++current_time;

  while(!visited_stack.empty()) {
    int current_label = visited_stack.top();

    // find no visited vertex
    int no_visited_label = no_label;
    for(int i = 0; i < vertex_num; i++) {
      if(matrices_graph[current_label - 1][i] != edge) {
        continue;
      }
      if(discovered_times[i] != no_time) {
        continue;
      }
      no_visited_label = i + 1;
      break;
    }

    if(no_visited_label != no_label) {
      visited_stack.push(no_visited_label);
      discovered_times[no_visited_label - 1] = ++current_time;
    } else {
      int finished_label = visited_stack.top();
      visited_stack.pop();

      finished_times[finished_label - 1] = ++current_time;
    }
  }

  return current_time;
}

int main() {
  int vertex_num;
  cin >> vertex_num;
  vector<vector<int>> matrices_graph(
    vertex_num,
    vector<int>(vertex_num, 0)
  );


  // set adjacency matrices graph
  for(int i = 0; i < vertex_num; i++) {
    int vertex_label;
    int adjacency_num;
    cin >> vertex_label >> adjacency_num;

    for(int j = 0; j < adjacency_num; j++) {
      int adjacency_label;
      cin >> adjacency_label;
      matrices_graph[vertex_label -1][adjacency_label - 1] = edge;
    }
  }

  vector<int> discovered_times(vertex_num, no_time);
  vector<int> finished_times(vertex_num, no_time);

  int current_time = 0;
  for(int i = 0; i <vertex_num; i++) {
    if(discovered_times[i] == no_time) {
      int started_label = i + 1;
      current_time = depth_search(
        started_label,
        current_time,
        matrices_graph,
        discovered_times,
        finished_times
      );
    }
  }

  for(int i = 0; i < vertex_num; i++) {
    cout << i + 1 << ' ' <<  discovered_times[i] << ' ' << finished_times[i] << endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1};
int dx[] = {1, -1, 0, 0};

int n;
int table[101][101];
int reached[101];
int back[101];
int bn = 1;
int cost = 1;
void dfs(int now) {
    //cout << bn << " " << now << " " << cost << endl;
    rrep(i, 1, n + 1) {
        if (table[now][i] == 1 && reached[i] == 0) {
            cost++;
            reached[i] = cost;
            bn = now;
            dfs(i);
        }
    }
    
    cost++;
    //cout << now << " " << cost << endl;
    back[now] = cost;
    return;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n + 1) rep(j, n + 1) table[i][j] = 0;
    rep(j, n) {
        int u, k; cin >> u >> k;
        int v;
        rep(l, k) {
            cin >> v;
            table[u][v] = 1;
        }
    }
    reached[1] = 1;
    dfs(1);
    rrep(i, 2, n + 1) {
        if (reached[i] == 0) {
            reached[i] = ++cost;
            dfs(i);
        }
    }
    rrep(i, 1, n + 1) cout << i << " " << reached[i] << " " << back[i] << endl;
    
}