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 <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
using namespace std;
const int64_t MOD = 1e9 + 7;

int n;
vector<vector<bool>> M(100, vector<bool>(100));
vector<int> C(100), d(100), f(100), nt(100);
int tt;

int next(int u) {
	for (int i = nt.at(u); i < n; i++) {
		nt.at(u) = i + 1;
		if (M.at(u).at(i)) return i;
	}
	return -1;
}

void dfs_visit(int r) {
	for (int i = 0; i < n; i++) nt.at(i) = 0;

	stack<int> S;
	S.push(r);
	C.at(r) = 1;
	d.at(r) = ++tt;

	while (!S.empty()) {
		int u = S.top();
		int v = next(u);

		if (v != -1) {
			if (C.at(v) == 0) {
				C.at(v) = 1;
				d.at(v) = ++tt;
				S.push(v);
			}
		}
		else {
			S.pop();
			C.at(u) = 2;
			f.at(u) = ++tt;
		}
	}
}

void dfs() {
	for (int i = 0; i < n; i++) {
		C.at(i) = 0;
		nt.at(i) = 0;
	}
	tt = 0;

	for (int i = 0; i < n; i++) {
		if (C.at(i) == 0) dfs_visit(i);
	}

	for (int i = 0; i < n; i++) {
		cout << i + 1 << ' ' << d.at(i) << ' ' << f.at(i) << endl;
	}
}

int main() {
	int u, k, v;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> v >> k;

		for (int j = 0; j < k; j++) {
			int x;
			cin >> x;
			M.at(v - 1).at(x - 1) = true;
		}
	}

	dfs();

	return 0;
}

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

//---------------------------------------------------------------
// ------ graph ------ //
using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
struct Graph {
    vector<Edges> adj;
    Graph(int n) : adj(n) { }
    int size() { return adj.size(); }
    Edges operator [] (int v) { return adj[v]; }
    void add_edge(int a, int b, Weight w = 1) { // graph
        adj[a].emplace_back(a, b, w);
        adj[b].emplace_back(b, a, w);
    }
    void add_arc(int a, int b, Weight w = 1) {  // digraph
        adj[a].emplace_back(a, b, w);
    }
};
using Array = vector<Weight>;
using Matrix = vector<Array>;
//---------------------------------------------------------------

using vi = vector<int>;
void dfs(int src, Matrix &M, vi &time_s, vi &time_t, int &time) {
    int n = M.size();
    time_s[src] = time++;
    for (int dst = 0; dst < n; dst++) {
        if (M[src][dst] && time_s[dst] < 0) {
            dfs(dst, M, time_s, time_t, time);
        }
    }
    time_t[src] = time++;
}

int main() {
    int n; cin >> n;
    Matrix M(n, Array(n, 0));
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        while (k--) {
            int v; cin >> v; M[u - 1][v - 1]++;
        }
    }
    vector<int> time_s(n, -1), time_t(n, -1);
    int time = 0;
    for (int i = 0; i < n; i++) if (time_s[i] < 0) {
        dfs(i, M, time_s, time_t, time);
    }
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << time_s[i] + 1 << " " << time_t[i] + 1 << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int graph[101][101]={};
int d[101]={};
int f[101]={};
int n,v,k,time1 = 0,sw[101] = {};


void dfs1(int u){

  sw[u] = 1;
  d[u] = ++time1;

  for(int i = 1; i <= n; i++){
    if( graph[u][i] == 1 && sw[i] == 0 ){
     dfs1(i);
    }

  }
    f[u] = ++time1;
}


int main(){
  int u;
  cin >> n ;
  //グラフをつくる
  for(int i = 0; i < n; i++){
    cin >> u >> k ;
    for(int j = 0; j < k ; j++){
      cin >> v;
      graph[u][v] = 1;
    }
  }

  dfs1(1);

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

  }
}

C++: #include<stdio.h>
int tu[1000][1000];
int a[10000];
int d[10000];
int f[10000];
int shijian,n;
void sou(int u){
     a[u]=2;
     d[u]=++shijian;
     for(int i=0;i<n;i++){
        if(tu[u][i]==0) continue;
        if(a[i]==1) {
            sou(i);
        }
     }
     a[u]=3;
     f[u]=++shijian;
}
void shensou(){
     for(int u=0;u<n;u++){
        a[u]=1;
     }
     shijian=0;
     for(int u=0;u<n;u++){
        if(a[u]==1)sou(u);
     }
     for(int u=0;u<n;u++){
         printf("%d %d %d\n",u+1,d[u],f[u]);
     }
}


int main(){
   int v;
   int m;
   int x;
   scanf("%d",&n);
   for(int i=0;i<n;i++){
        scanf("%d%d",&v,&m);
        v--;
        for(int j=0;j<m;j++){
            scanf("%d",&x);
            x--;
            tu[v][x]=1;
        }
   }
   shensou();
return 0;
}