Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	timer := 1
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	return x
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int n; //頂点数
vector<vector<int> > g;//グラフ
vector<int>d;//到着時刻を記録
vector<int>f;//終了時刻を記録
void dfs(int v,int& i) {
    if(d[v] == 0) {
        i++;
        d[v] = i;//到着時刻を記録
    }    
    
    for(int next_v : g[v]) {
        if(d[next_v]) continue;//訪問済みなら飛ばす
        dfs(next_v,i);//隣接頂点について探索
    }
    if(f[v] == 0) {
        i++;
        f[v] = i;//終了時刻を記録
    }
}
int main() {
    cin >> n;
    //nで初期化
    g.resize(n);
    f.resize(n);
    d.resize(n);
    rep(i,n) {
        int u; //頂点番号
        cin >> u;
        u--;
        int k; //出次数
        cin >> k;
        rep(j,k) {
            int v;//隣接する頂点
            cin >> v;
            v--;
            g[u].push_back(v);
        }
    }
    int count = 0;
    //各頂点からdfs
    for(int i = 0;i<n;i++) {
        dfs(i,count);
    }    
    //各頂点について到着時刻と終了時刻を出力
    for(int i = 0;i<n;i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include<stack>
#include <algorithm>
using namespace std;
#define max 101
#define WHITE 0
#define BLACK 1
#define GRAY -1
int color[max],d[max],f[max];
int t,varry[max][max];
stack<int> s;
int next(int u){
  int nv=-1;
  for(int i=0;i<varry[u][0];i++){
    if(color[varry[u][i+1]]==WHITE){
      nv=varry[u][i+1];
      break;
    }
  }
  
  return nv;
}
void visit(int r){
  int u,v;
  s.push(r);
  color[r]=GRAY;
  d[r]=++t;
  while(!s.empty()){
    u=s.top();
    v=next(u);
    if(v!=-1){
      if(color[v]==WHITE){
	s.push(v);
	color[v]=GRAY;
	d[v]=++t;
      }
    }
    else{
      s.pop();
      color[u]=BLACK;
      f[u]=++t;
      
    }
  }
}
void dfs(int u){
  for(int i=1;i<=u;i++)
    if(color[i]==WHITE)visit(i);
}
int main(){
  int n,u;
  cin>>n;
  for(int k=0;k<n;k++){
    cin>>u;
    cin>>varry[u][0];
    for(int i=0;i<varry[u][0];i++)
      cin>>varry[u][i+1];

  }
  dfs(n);
  for(int i=1;i<=n;i++){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
  }


  return 0;
}

C++: #include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
const int INF = 0x7fffffff;

int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}

using Graph = vector<vector<int>>;

int g[101][101];
int seen[101];
int stamp[2][101];
int n;
int t;

void dfs(int v){
  seen[v] = 1;
  int ii;

  //cout << v << endl;
  
  stamp[0][v] = t;
  t++;

  //for(ii=1;ii<=n;ii++){
  //  cout << seen[ii] << endl;
  //}
  
  for(ii=1;ii<=n;ii++){
    //cout << "v:"<< v << "ii:" << ii << " " << g[v][ii] << endl;

    if(seen[ii] == 1){continue;}
    //cout << "v:"<< v << "ii:" << ii << " " << g[v][ii] << endl;

    if(g[v][ii] == 1){
      dfs(ii);
    }
  }
  
  stamp[1][v] = t;
  t++;
}

int main(){
  long ii,jj,kk;
  vector<int> a;


  memset(g,0,sizeof(g));

  memset(stamp,0,sizeof(stamp));
  
  cin >> n;

  int v,vn,r;
  
  for(ii=0;ii<n;ii++){
    cin >> v;
    cin >> vn;
    for(jj=0;jj<vn;jj++){
      cin >> r;
      g[v][r] = 1;
    }
  }

  //for(ii=1;ii<=n;ii++){
  //  for(jj=1;jj<=n;jj++){
  //    cout << g[ii][jj] ;
  //    if(jj!=n){
  //      cout << " ";
  //    }
  //  }
  //  cout << endl;
  //}  
  
  t = 1;
  memset(seen,0,sizeof(seen));

  for(ii=1;ii<=n;ii++){
    if(seen[ii] == 0){
      dfs(ii);
    }

  }


  for(ii=1;ii<=n;ii++){
    cout << ii << " " << stamp[0][ii] << " " << stamp[1][ii] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<vector<int>> edge(n);
    for (int i = 0; i < n; i++) {
        int m, c;
        cin >> m >> c;
        for (int j = 0; j < c; j++) {
            int x;
            cin >> x;
            edge[i].push_back(--x);
        }
    }

    int timestamp = 1;
    vector <int> d(n, -1), f(n, -1);
    auto dfs = [&](auto dfs, int cur) -> void {
        d[cur] = timestamp++;
        for (int ch : edge[cur]) {
            if (d[ch] == -1) {
                dfs(dfs, ch);
            }
        }
        f[cur] = timestamp++;
    };

    for (int i = 0; i < n; i++) {
        if (d[i] == -1) {
            dfs(dfs, i);
        }
    }

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

    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
bool visit[100];
int finish_time[100];
int find_time[100];
int t;
vector<int> E[100];
void dfs(int u){
  visit[u] = true;
  find_time[u] = ++t;
  for(int v : E[u]) if(!visit[v]) dfs(v);
  finish_time[u] = ++t;
}

int main(){
  int n;
  cin >> n;
  rep(i,n){
    int u,k;
    cin >> u >> k;
    u--;
    rep(j,k){
      int v;
      cin >> v;
      v--;
      E[u].push_back(v);
    }
  }
  rep(i,n) if(!visit[i]) dfs(i);
  rep(i,n){
    cout << i+1 << " " << find_time[i] << " " << finish_time[i] << endl;
  }
  return 0;
}