Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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