Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000

vector<int> V[100];//0 origin
bool complete[100] = {};
stack<int> S;
int time_ = 1;
int NodeStump[100][2] = {};//find,end

void DFS(){
    if (S.empty()) return;
    NodeStump[S.top()][0] = time_;
    time_++;
    
    REP1(i,V[S.top()].size()){
        if (NodeStump[V[S.top()][i]][0] == 0){
            S.push(V[S.top()][i]);
            DFS();
        }
    }
    
    complete[S.top()] = true;
    NodeStump[S.top()][1] = time_;
    S.pop();
    time_++;
}

int main(){
    INT(N);
    
    REP1(i,N){
        int from,n;
        scanf("%d %d",&from,&n);
        REP1(j,n){
            INT(to);
            V[i].push_back(to - 1);
        }
    }
    
    REP1(i,N){
        if(!complete[i]){
        S.push(i);
        DFS();
        }
    }
    
    REP1(i,N) printf("%d %d %d\n",i+1,NodeStump[i][0],NodeStump[i][1]);
    
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int> > G;
int d[111],f[111],u[111];
void dfs(int v,int& p){
  if(u[v]) return;
  u[v]=1;
  sort(G[v].begin(),G[v].end());
  d[v]=++p;
  for(int u:G[v]) dfs(u,p);
  f[v]=++p;
}
signed main(){
  int n;
  cin>>n;
  G.resize(n,vector<int>());
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      c--;
      G[u].push_back(c);
    }
  }
  int p=0;
  for(int i=0;i<n;i++)
    if(!u[i]) dfs(i,p);
  for(int i=0;i<n;i++) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;;
  return 0;
}

C++: #include<iostream>
int a[101][101]={0};
int d[101]={0};//vを最初に発見した発見時刻
int f[101]={0};//vの隣接リストを調べ終えた完了時刻
int used[101]={0};//見つけたかどうか
int t=1;
int n;

void search(int i){
  d[i]=t++;
  used[i]++;
  int j;
  for(j=0; j<n; j++){
    if(a[i][j]==1 and used[j]==0){
      search(j);
    }
  }
  f[i]=t++;
}
int main(){
  int k;
  int u,v;
  std::cin>>n;
  int i,j;
  //行列の初期化
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      a[i][j]=0;
    }
  }
  for(i=0; i<n; i++){
    std::cin>>u;
    std::cin>>k;
    for(j=0; j<k; j++){
      std::cin>>v;
      a[u-1][v-1]=1;
    }
  }
  for(i=0; i<n; i++){
    if(used[i]==0){
      search(i);
    }
  }
  for(i=0; i<n; i++){
    std::cout<<i+1<<" "<<d[i]<<" "<<f[i]<<"\n";
  }
  return 0;
}

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

int N;
int G[105][105];
int d[105], f[105];
int used[105];

int dfs(ll v, ll t) {
  used[v] = true;
  d[v] = t;
  for (ll i = 0; i < N; i++) {
    if (!used[i] && G[v][i]) {
      t = dfs(i, t + 1);
    }
  }
  return f[v] = t + 1;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> N;
  for (ll i = 0; i < N; i++) {
    ll U, K; cin >> U >> K;
    for (ll j = 0; j < K; j++) {
      ll v; cin >> v; v--;
      G[i][v] = 1;
    }
  }

  int t = 0;
  for (ll i = 0; i < N; i++) {
    if (!used[i]) {
      t = dfs(i, t + 1);
    }
  }

  for (ll i = 0; i < N; i++) {
    cout << (i + 1) << ' ' << d[i] << ' ' << f[i] << '\n';
  }
  return 0;
}

C++: #include <utility>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int c;
int a[100][100];
int times = 0;
vector<pair<int,int> > v;

vector<int> search(int node)
{
    vector<int> r;
    for(int i = 0;i<c;i++)
    {
        if(a[node][i] == 1)
            r.push_back(i);
    }
    return r;
}

int deep(int node)
{
    if(v[node].first == 0)
    {
        v[node].first = ++times;
        vector<int> r = search(node);
        for(int i = 0;i<r.size();i++)
        {
            deep(r[i]);
            
        }
        v[node].second = ++times;
    }
    else
        return -1;

    return 1;
}

int main() {

    cin >> c;
    for(int i= 0;i<c;i++)
        for(int j = 0;j<c;j++)
            a[i][j] = 0;
    v = vector<pair<int,int> >(c,{0,0});
    for(int i = 0; i<c;i++)
    {
        int rem[2];
        cin >> rem[0] >> rem[1];
        for(int j = 0;j<rem[1];j++)
        {
            int rem11;
            cin >> rem11;
            a[i][rem11-1] = 1;
        }
    }//cin fin
    deep(0);
    
    for(int i = 0; i<c;i++)
    {
        cout << i+1 << " " << v[i].first << " " << v[i].second << endl;
    }
    
    return 0;
}

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

using namespace std;

int verticisNumber;
vector<int> d, f;
vector< vector<int> > g;

void dfs(int cur) {
    static int time = 0;
    time++;
    d[cur] = time;

    for(int i = 0; i < verticisNumber; i++) {
        if(g[cur][i] && !d[i]) {
            dfs(i);
        }
    }

    time++;
    f[cur] = time;

    return;
}

int main() {
    cin >> verticisNumber;
    d.resize(verticisNumber); f.resize(verticisNumber);
    g.resize(verticisNumber);
    for(auto itr = g.begin(); itr != g.end(); itr++) {
        itr->resize(verticisNumber);
    }

    for(int i = 0; i < verticisNumber; i++) {
        int k, degree;
        cin >> k >> degree;
        for(int j = 0; j < degree; j++) {
            int dst;
            cin >> dst;
            g[i][dst - 1] = 1;
        }
    }

    for(int i = 0; i < verticisNumber; i++) {
        if(!d[i]) {
            dfs(i);
        }
    }

    for(int i = 0; i < verticisNumber; i++) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}