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;

const int SIZE = 100;
int Adj[SIZE][SIZE+3];
int d[SIZE];
int f[SIZE];
int t=0;

void DFS(int id){
    
    //t++;

    // タイムスタンプが押されている
    if (d[id-1] != 0){
        return;
    }

    d[id-1] = ++t;

    for(int i=2;Adj[id-1][i]!=0;i++){
        DFS(Adj[id-1][i]);
    }

    f[id-1] = ++t;
}

int main(){
    int n;
    cin >> n;
    
    // 初期化
    for(int i=0;i<SIZE;i++){
        d[i] = 0;
        f[i] = 0;
        for(int j=0;j<SIZE+3;j++){
            Adj[i][j] = 0;
        }
    }

    // 入力受付
    for(int i=0;i<n;i++){
        cin >> Adj[i][0] >> Adj[i][1];
        for(int j=0;j<Adj[i][1];j++){
            cin >> Adj[i][j+2];
        }
    }

    for(int i=1;i<=n;i++){
        if(d[i-1]!=0){
            continue;
        }
        DFS(i);
    }

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

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<P> ans;
vector<vector<int>> e;

int dfs(int nn, int time) {
    // 探れるところがあるか探す
    if (ans[nn].first == 0) {
        // 到達していなければ時間を足して記録
        time += 1;
        ans[nn].first = time;
        // cout << "achived " << nn << ": " << time << endl; 
    }
    rep(i, e[nn].size()) {
        if (ans[e[nn][i]].first != 0) continue;
        // 到達していない箇所があれば入る
        time = dfs(e[nn][i], time);
    }
    time += 1;
    ans[nn].second = time;
    return time;
}

int main() {
    cout << fixed << setprecision(10);
    
    int n; cin >> n;
    // vector<vector<int>> e(n);
    e.resize(n);
    rep(i, n) {
        int id; cin >> id; id--;
        int k; cin >> k;
        rep(j, k) {
            int v; cin >> v; v--;
            e[id].emplace_back(v);
        }
    }

    // vector<P> ans(n);
    ans.resize(n);
    int time = 0;
    rep(i, n) {
        if (ans[i].first == 0) {
            time = dfs(i, time);
        }
    }
    rep(i, n) {
        cout << i+1 << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1 
#define BLACK 2
 
int n, M[N][N];
int color[N], d[N], f[N], tt; 

void dfs_visit(int u) {
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	for(v = 0; v < n; v++) {
		if(M[u][v] == 0) continue;
		if(color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs() {
	int u;
	for(u = 0; u < n; u++) color[u] = WHITE;
	tt = 0;
	
	for(u = 0; u < n; u++) {
		if(color[u] == WHITE) dfs_visit(u);
	}
	
	for(u = 0; u < n; u++) {
		printf("%d %d %d\n", u + 1, d[u], f[u]);
	}
}
 
int main() {
    int u, k, v, i, j;
    
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        M[i][j] = 0;
      } 
    }
    
    for(int i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        u--;
        for(int j = 0; j < k; j++ ) {
           scanf("%d", &v);
           v--;
           M[u][v] = 1; 
        }       
    }
     
     
    dfs();
     
    return 0;
}

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

int n, dd[100], f[100], tmap[100][100];
int color[100], t = 1;
stack<int> S;

int a(){
	int d = S.top();
	dd[d] = t;
	t++;
	color[d] = 1;
	cout << d << "??????" <<endl;
	for (int i = 1; i <= n; i++){
		if (color[i] == 0 && tmap[d][i] == 1){
			cout << d << "  " << i << "  " << t << endl;
			S.push(i);
			a();
		}
	}
	cout << d << "??????" << endl;
	f[d] = t;
	t++;
	return 0;
}


int main(){
	cin >> n;
	for (int i = 0; i < 100; i++){
		dd[i] = f[i] = color[i] = 0;
		for (int j = 0; j < 100; j++){
			tmap[i][j] = 0;
		}
	}

	int u, k, v;

	for (int i = 0; i < n; i++){
		cin >> u >> k;
		for (int j = 0; j < k; j++){
			cin >> v;
			tmap[u][v] = 1;
		}
	}
	S.push(1);
	a();
	for (int i = 1; i <= n; i++){
		cout << i << " " << dd[i] << " " << f[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > v(101);
int dp[101][2] = { 0 };
int n, t = 0;

void dfs(int a) {
	t++;
	if (dp[a][0] == 0) { dp[a][0] = t; }
	for (int i = 0;i < v[a].size();i++) {
		if (dp[v[a][i]][0] == 0) {
			dfs(v[a][i]);
		}
	}
	t++;
	if (dp[a][1] == 0) { dp[a][1] = t; }
}

int main() {
	cin >> n;
	for (int i = 0; i < n;i++) {
		int u,k; cin >> u >> k;
		for (int j = 0; j < k;j++) {
			int x; cin >> x;
			v[u].push_back(x);
		}
	}
	dfs(1);
	for (int i = 1; i <= n;i++) {
		cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << endl;
	}
}

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

stack<int> S;
int n, x[10000][10000], a, b, c, d, _time=2;
int y[10000][3];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> b >> c;
		for (int j = 1; j <= c; j++) {
			cin >> d;
			x[i][d] = 1;
			x[d][i] = 1;
		}
	}
	S.push(1);
	y[1][1] = 1;
	while (!S.empty()) {
		a = S.top();
		for (int i = 1; i <= n; i++) {
			if (x[a][i] == 1 && y[i][0] == 0) {
				y[i][0] = 1;
				y[i][1] = _time;
				S.push(i);
				goto Exit;
			}
		}
		S.pop();
		y[a][2] = _time;
	Exit:;
		_time++;
	}
	for (int i = 1; i <= n; i++) {
		cout << i << ' ' << y[i][1] << ' ' << y[i][2] << endl;
	}
	return 0;
}