Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

func next(u int) int {
	for v := nt[u]; v < n; v++ {
		nt[u] = v + 1
		if Adj[u][v] == 1 {
			return v
		}
	}
	return -1
}

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
#include <list>
using namespace std;

int n;

struct Node{
public:
  int id, d, f, flag;
  vector<int> c;
  Node(){d = 1000000007;f = flag = 0;}
};

vector<Node> v(101);

void rec(int id, int &t){
  if(v[id].flag)return;
  else          v[id].flag = 1;
  v[id].d = min(v[id].d, ++t);
  for(int i=0;i<v[id].c.size();i++) {
    rec(v[id].c[i], t);
  }
  v[id].f = max(v[id].f, ++t);
}


bool asc(const Node &right, const Node &left){return right.id < left.id;}

int main(){
  cin >> n;
  
  v[0].id = 0;  
  for(int i=1;i<=n;i++){
    int t, a;  cin >> a >> t;
    vector<int> b(t);
    for(int j=0;j<t;j++){
      int val;cin >> val;
      b[j] = val;
    }
    v[a].id = a;
    v[a].c = b;
  }
  sort(v.begin(), v.end(), asc);

  int ti = 0;
  for(int i=1;i<=n;i++){
    rec(i, ti);
  }

  for(int i=1;i<=n;i++){
    printf("%d %d %d\n", v[i].id, v[i].d, v[i].f);
  }
  return 0;
}

C++: #include <stdio.h>

int numberd=1, numberf=1;
int map[100][100];
int numofroot[100];
int visited[100];
int d[100];
int f[100];
int map_size;
 
void get_map();
void print_map();
int search(int node);
void print_result();
int main()
{
  get_map();
  //print_map();
  for(int i=0;i<map_size;i++)
    {
      if(d[i]==0)
	{
	  search(i);
	}
    } 
  print_result();
  return 0;
}

int search(int node)
{
  int k;
  if(d[node]==0)//not visited
    {
      d[node]=numberd;//visited
      numberd++;
      if(numofroot[node]!=0)
	{
	  for(int i=0;i<numofroot[node];i++)
	    {
		{
		  k=search(map[node][i]-1);
		  if(k==-1)
		    {
		      //f[node]=numberd;
		      //numberd++;
		      //return -1;
		    }
		}
	    }
	}
      //else
	{
	  f[node]=numberd;
	  numberd++;
	  return -1;
	}
    }
  else//visited
    {
      return 1;
    }

  return -1;
}

void print_result()
{
  for(int i=0;i<map_size;i++)
    {
      printf("%d %d %d\n",i+1, d[i],f[i]);
    }
  return ;
}

void get_map()
{
  int k;
   scanf("%d", &map_size);
  for(int i=0;i<map_size;i++)
    {
      scanf("%d", &k);
      scanf("%d", &numofroot[i]);
      for(int j=0;j<numofroot[i];j++)
	{
	  scanf("%d", &map[i][j]);
	}
    }
  return ;
}

void print_map()
{
  for(int i=0;i<map_size;i++)
   {
     printf("%d", numofroot[i]);
     for(int j=0;j<numofroot[i];j++)
       {
	 printf("%d", map[i][j]);
       }
     if(i!=map_size-1)
       {
     puts("");
       }
   }
  puts("");
  return ;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

vector<vector<ll>> G;
vector<ll> d, f;
vector<bool> b;
ll t;

ll dfs(ll v, ll t) {
    b[v] = true;
    d[v] = t;
    for (auto nv : G[v]) {
        if (b[nv]) continue;
        t = dfs(nv, t + 1);
    }
    f[v] = t + 1;
    return t + 1;
}

int main() {
    ll n;
    cin >> n;
    G.resize(n), d.resize(n), f.resize(n), b.resize(n);
    rep(i, n) {
        ll u, k;
        cin >> u >> k;
        u--;
        rep(j, k) {
            ll v;
            cin >> v;
            v--;
            G[u].emplace_back(v);
        }
    }
    ll now = 0;
    rep(i, n) {
        if(b[i]) continue;
        now = dfs(i, now + 1);
    }
    rep(i, n) cout << i+1 << " " << d[i] << " " << f[i] << endl;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;++i)

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

int hlt = 0;
vector<P> times;
vector<vector<int>> node;
vector<bool> searched;

void solve(int index){
    if(!searched[index])searched[index]=true;else return;
    times[index].first=++hlt;
    REP(i,(int)node[index].size())
        solve(node[index][i]-1);
    times[index].second=++hlt;
}

int main(){
    int n; cin>>n;
   node.resize(n);
   times.resize(n,P(0,0));
   searched.resize(n,false);
   REP(i,n){
    int index,size; cin >> index >> size; index--;
    if(size==0)continue;
    node[index].resize(size);
        REP(j,size)cin >> node[index][j];
    sort(node[index].begin(),node[index].end());
   }
   REP(i,n)
    if(!searched[i])
        solve(i);
   REP(i,n)
    cout<<i+1<<" "<<times[i].first<<" "<<times[i].second<<endl;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

typedef struct{
  int begin;
  int end;
  bool f;
}fint;
fint T[101];

int times = 1;
int n;
int graph[101][101];

void bfs(int now){

  T[now].f = true;
  T[now].begin = times++;

  for( int i = 1 ; i <= n; i++ ){
    if( graph[now][i] == 1 && !T[i].f ) bfs(i);
  }
  T[now].end = times++;

}

int main(void){

  int s,t,u;
  cin >> n;
  for( int i = 0 ; i < n ; i++ ){
    cin >> s >> t;
    for( int j = 1 ; j <= t ; j++ ){
      cin >> u;
      graph[s][u] = 1;
    }
  }
  for( int i = 1 ; i <= n ; i++ ){
    T[i].begin = 0;
    T[i].end = 0;
    T[i].f = false;
  }
  for( int i = 1 ; i <= n ; i++ ){
    if( !T[i].f ) bfs(i);
  }

  for( int i = 1 ; i <= n ; i++ ){
    cout << i << " " << T[i].begin << " " << T[i].end << endl;
  }


  return 0;
}