Go: package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<array>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int long long ll;
static const int N=100;
static const int white=0;
static const int gray=1;
static const int black=2;

int n,d[N],f[N],tt;
int color[N],nt[N];
int mp[N][N];

int next(int u){
    
    for(int v=nt[u];v<n;v++){
        nt[u]=v+1;
        if(mp[u][v]!=0)return v;
    }
    return -1;
}


void dfs_visit(int r){
    
    rep(i,n)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){
            d[v]=++tt;
            color[v]=gray;
            s.push(v);
            }
        }else{
            color[u]=black;
            f[u]=++tt;
            s.pop();
        }
    }
}



void dfs(){

    rep(i,n){color[i]=white;nt[i]=0;}
    tt=0;
    
    for(int i=0;i<n;i++){
        if(color[i]==white){
            dfs_visit(i);
        }
    }
    rep(i,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    
}

int main(){
    cin>>n;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            mp[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        rep(j,b){
            int c;
            cin>>c;
            mp[a-1][c-1]=1;
        }
    }
    
    dfs();
    
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int n;
vector<int> u, k;
vector<int> d, f;
vector<vector<int>> v;

int a = 0;
void dfs(int _n) {
  a++;
  d[_n] = a;
  for(int i = 0; i < k[_n]; ++i) {
    if(d[v[_n][i] - 1] != 0) {
      continue;
    }
    dfs(v[_n][i] - 1);
  }
  a++;
  f[_n] = a;
}

int main() {
  cin >> n;
  u.resize(n); k.resize(n);
  d.assign(n, 0); f.assign(n, 0);
  v.resize(n);
  REP(i, n) {
    cin >> u[i] >> k[i];
    REP(m, k[i]) {
      int a; cin >> a;
      v[i].push_back(a);
    }
  }
  for(int i = 0; i < n; ++i) {
    if(d[i] == 0) dfs(i);
  }
  REP(i, n) {
    cout << u[i] << " " << d[i] << " " << f[i] << endl;
  }
}

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