Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

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

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

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

C++: #include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int t;
vector< vector<int> > A;
vector<int> c;
vector<int> d;
vector<int> f;

void dfsVisit(int u) {
    t++;
    d[u] = t;
    c[u] = 1;
    for(int i=0; i<A[u].size(); i++) {
        int v = A[u][i];
        if(c[v] == 0) dfsVisit(v);
    }
    t++;
    f[u] = t;
}

void dfs() {
    for(int u=0; u<n; u++) c[u] = 0;
    t = 0;
    for(int u=0; u<n; u++) {
        if(c[u] == 0) {
            dfsVisit(u);
        }
    }
}

int main() {
    cin >> n;
    A.resize(n);
    c.resize(n);
    d.resize(n);
    f.resize(n);

    for(int i=0; i<n; i++) {
        int u,k;
        cin >> u >> k;
        A[u-1].resize(k);
        for(int j=0; j<k; j++) {
            int v;
            cin >> v;
            A[u-1][j] = v-1;
        }
        sort(A[u-1].begin(), A[u-1].end());
    }

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

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int V;
Graph G;
vector<int> d;
vector<int> f;
vector<int> color;

#define WHITE 0
#define GRAY 1
#define BLACK 2

int now;

void dfs(const Graph &G, int v){
    color[v] = GRAY;
    d[v] = ++now;
    for(auto nv : G[v]){
        if(color[nv]==WHITE){
            dfs(G, nv);
        }
    }
    color[v] = BLACK;
    f[v] = ++now;
}

int main()
{
    now = 0;
    cin >> V;
    G.resize(V);
    d.assign(V, -1);
    f.assign(V, -1);
    color.assign(V, 0);
    rep(j, V)
    {
        int from;
        cin >> from;
        --from;
        int k;
        cin >> k;
        rep(i,k){
            int to;
            cin >> to;
            --to;
            G[from].push_back(to);
        }
    }
    for (int i = 0; i < V; i++){
        if(color[i] == WHITE)
            dfs(G, i);
    }

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

C++: #include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

vector<UL> E[100];
UL ans[100][2]={};
UL tp=0;
bool F[100]={};

void DFS(UL p){
 F[p]=true;
 tp++; ans[p][0]=tp;
 for(UL e:E[p]){
  if(F[e]) continue;
  DFS(e);
 }
 tp++; ans[p][1]=tp;
}

int main() {
 UL N; scanf("%u",&N);
 rep(i,N){
  UL v; scanf("%u",&v); v--;
  UL c; scanf("%u",&c);
  rep(i,c){
   UL e; scanf("%u",&e); e--;
   E[v].push_back(e);
  }
 }
 rep(i,N) if(!F[i]) DFS(i);
 rep(i,N) printf("%u %u %u\n",i+1,ans[i][0],ans[i][1]);
 return 0;
}

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

#define int long long

const int N = 100 + 3;
vector<int> g[N];
int time_entry[N];
int time_exit[N];
bool visited[N];
int dfs_timer = 1;

void dfs(int s){
   	visited[s] = true;
    time_entry[s] = dfs_timer++;
   	for(auto it : g[s]){
	  if (!visited[it]) dfs(it);	  	
	}
	time_exit[s] = dfs_timer++;
}
	
int32_t main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) visited[i] = false;
  for(int i = 0; i < n; i++){
	  int m, deg;
	  cin >> m >> deg;
	  m--;
	  for (int i = 0; i < deg; i++){
		  int x;
		  cin >> x;
		  x--;
		  g[m].push_back(x);  
	  }  
   }
  for(int i = 0; i < n; i++){
	    if (!visited[i]) dfs(i);
	}
  for(int i = 0; i < n; i++){
	   int idx = i + 1;
	   cout << idx << " "<< time_entry[i] <<  " "<< time_exit[i] << endl;  
	}     	
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


void dfs(vvi g,int v, int &time,vb &seen,vi &first_time,vi &last_time) {
  first_time[v]=++time;
  seen[v]=true;
  for(auto next_v:g[v]) {
    if(seen[next_v]) continue;
    dfs(g,next_v,time,seen,first_time,last_time);
  }
  last_time[v]=++time;
}

int main() {
  int n;
  cin >> n;
  vvi G(n);
  REP(i,n) {
    int a;
    cin >> a;
    a--;
    int k;
    cin >> k;
    REP(j,k) {
      int b;
      cin >> b;
      b--;
      G[a].push_back(b);
    }
  }
  int time=0;
  vb seen(n,false);
  vi first_time(n,1);
  vi last_time(n,1);
  REP(i,n) {
    if(seen[i]) continue;
    dfs(G,i,time,seen,first_time,last_time);
  }
  REP(i,n) {
    cout << i+1 << " " << first_time[i] << " " << last_time[i] << endl;
  }
  return 0;
}