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>
using namespace std;

struct node
{long long v; struct node *next;};

struct node *z;

void visit(long long k,  struct node **adj, long long &time, long long d[], long long f[]){
    struct node *t;
    d[k] = ++time;
    for(t = adj[k]; t != z; t = t -> next){
        if(d[t -> v] == 0) visit(t -> v, adj, time, d, f);
    }
    f[k] = ++time;
}
void search(long long V, struct node **adj, long long &time, long long d[], long long f[]){
    long long k;
    for(k = 1; k <= V; k++) d[k] = 0;
    for(k = 1; k <= V; k++){
        if(d[k] == 0) visit(k, adj, time, d, f);
    }
}

int main(){

    //adjacency list representation
    long long V, E;
    cin >> V;
    struct node *adj[V + 1];
    long j, k, x, y[V + 1];
    struct node *t;
    z = new node;
    z -> next = z;
    for(j = 1; j <= V; j++) adj[j] = z;
    for(j = 1; j <= V; j++){
        cin >> x >> E;
        for(k = 1; k <= E; k++){
            cin >> y[k];
        }
        for(k = E; k >= 1; k--){
            t = new node;
            t -> v = y[k];
            t -> next = adj[x];
            adj[x] = t;
        }
    }

    //depth first search
    long long time = 0;
    long long d[V + 1];
    long long f[V + 1];
    search(V, adj, time, d, f);
    for(j = 1; j <= V; j++){
        cout << j << " " << d[j] << " " << f[j] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int adj[105][105] = {0};
int res[105][2] = {0};
int t = 1;
int n;

int dfs(int start){
    if(res[start][0] == 0)
        res[start][0] = t;
    t++;
    REP(i, n)
        if(adj[start][i] != 0 && res[i][0] == 0)
            dfs(i);
    res[start][1] = t;
    t++;
    return 0;
}

int main() {
    cin >> n;
    REP(i, n){
        int u, k;
        cin >> u >> k;
        REP(j, k) {
            int tmp;
            cin >> tmp;
            adj[u-1][tmp-1] = 1;
        }
    }
    REP(i, n)
        if(res[i][0] == 0)
            dfs(i);
    REP(i, n)
        cout << i+1 << " " << res[i][0] << " " << res[i][1] << endl;
    return 0;
}

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