Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 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;
    }
}