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) doesAllAdjsVisited(vertices []vertex) bool {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return false
		}
	}
	return true
}

func (v *vertex) isFirstVisit() bool {
	return v.firstVisitAt == 0
}

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

func (v *vertex) nextVertex(vertices []vertex) (vertexId, error) {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return vId, nil
		}
	}
	return vertexId(-1), fmt.Errorf("illegal")
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	timestamp = timestamp + 1
	currentVertex := &vertices[currentId-1]
	if currentVertex.isFirstVisit() {
		currentVertex.firstVisitAt = timestamp
	}
	for !currentVertex.doesAllAdjsVisited(vertices) {
		nextVertexId, _ := currentVertex.nextVertex(vertices)
		timestamp = dfs(nextVertexId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

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

	dfs(vertexId(1), 0, 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<stack>
using namespace std;
static const int N = 100; 
static const int WHITE = 0;
static const int GRAY = 1; 
static const int BLACK = 2;

int M[N][N], color[N], d[N], f[N], nt[N];
int tt,n;

int next(int u) {
	for(int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
	    if(M[u][v]) return v;
	}
	return -1;
}

void dfs_visit(int r) {
	for(int i = 0; i < n; i++) nt[i] = 0;
	
	stack<int> S;
	S.push(r);
	color[r] = BLACK;
	d[r] = ++tt;
	
	while(!S.empty()) {
		int u = S.top();
		int v = next(u);
		if(v != -1) {
			if(color[v] == WHITE) {
			   color[v] = GRAY;
			   d[v] = ++tt;
			   S.push(v);	
			}
		} else {
			S.pop();
			color[u]  = BLACK;
			f[u] = ++tt;
		}
	}
}


void dfs() {
	for(int i = 0; i < n; i++){
		color[i] = WHITE; nt[i] = 0;
	}
	tt = 0; 
	
	for(int j = 0; j < n; j++) {
		if(color[j] == WHITE) {
			dfs_visit(j);
		}
	}
	
	for(int i =0; i < n; i++ ) {
    	cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}
}


int main() {
	int u, k,v;
	cin >> n;
	for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
      	M[i][j] = 0;
      }	
	}
	cin >> u >> k ;
	u--;
	for(int i = 0; i < k; i++ ) {
	   cin >> v;
	   v--;
	   M[u][v] = 1;	
	}	
	
	dfs();
	
	return 0;
}

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

int n;
vector<int> g[110];
int in[110], out[110];

void dfs(int v, int& t) {
    in[v] = ++t;
    for (int nv : g[v]) if (!in[nv]) {
        dfs(nv, t);
    }
    out[v] = ++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 v;
            cin >> v;
            g[u - 1].push_back(v - 1);
        }
    }
    int t = 0;
    for (int i = 0; i < n; ++i) if (!in[i]) {
        dfs(i, t);
    }
    for (int i = 0; i < n; ++i) {
        cout << i + 1 << " " << in[i] << " " << out[i] << endl;
    }
}

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int n, i, j, u, v, k;
bool is_connected[150][150];

// 最初に発見した時刻
int d[150];
// 隣接リストを調べ終えた時刻
int f[150];

void init() {
    rep(i, n + 1) rep(j, n + 1) is_connected[i][j] = false;
    rep(i, n + 1) {
        d[i] = 0;
        f[i] = 0;
    }
    d[1] = 1;
}

// must handle infinite loop
int walkDepthFirst(int src_id, int time) {
    d[src_id] = time;

    int dst_id;
    rep(dst_id, n + 1) {
        if (is_connected[src_id][dst_id]) {
            // 未訪問
            if (d[dst_id] == 0) {
                time = walkDepthFirst(dst_id, time + 1);
            }
        }
    }

    time++;
    f[src_id] = time;
    return time;
}

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

    rep(i, n) {
        cin >> u >> k;
        rep(j, k) {
            cin >> v;
            is_connected[u][v] = true;
        }
    }

    int time = 1;
    int node = 1;
    // rep(i, n) {
    //     int cur_node = i + 1;
    //     if (d[cur_node] == 0 && f[cur_node] == 0) {
    //         time = walkDepthFirst(cur_node, time);
    //         time++;
    //     }
    // }

    time = walkDepthFirst(node, time);

    rep(i, n) {
        int cur_node = i + 1;
        if (d[cur_node] == 0) {
            time = walkDepthFirst(cur_node, time + 1);
        }
    }

    rep(i, n) {
        cout << i + 1 << " " << d[i + 1] << " " << f[i + 1] << endl;
    }

    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack<int> st;
int  v[102][101], n;
int  tim[102][2];
int ct = 1;
int go[102];
inline void search(int t) {
	if(!tim[t][0]) tim[t][0] = ct++;
	go[t] = 1;
	int tf = 0;
	for (int a = 1; a <= n; a++) {
		if (v[t][a]) {
			st.push(a);
			for (int i = 1; i <= n; i++) {
				v[i][a] = 0;
			}
			search(st.top());
			tf = 1;
		}
	}
		
	if(!tf) {
		st.pop();
		tim[t][1] = ct++;
		if(!st.empty()) search(st.top());
	}
}
int main() {

	st.push(1);
	int u, k, s;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			v[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			v[u][s] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		v[i][1] = 0;
	}
	search(1);
	for (int i = 2; i <= n; i++) {
		if (!go[i]) {
			st.push(i);
			for (int j = 1; j <= n; j++) {
				v[j][i] = 0;
			}
			search(i);
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << i << " " << tim[i][0] << " " << tim[i][1] << endl;
	}
	return 0;
}

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

vector<int> graph[100];
int start[100],endt[100];
int cnt;

void dfs(int num){
	start[num] = ++cnt;
	for(int i = 0;i < graph[num].size();i++){
		if(!endt[graph[num][i]]) dfs(graph[num][i]);
	}
	endt[num] = ++cnt;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int now,m;
		cin >> now >> m;
		for(int j = 0;j < m;j++){
			int t;
			cin >> t;
			graph[now - 1].push_back(t - 1);
		}
	}
	dfs(0);
	for(int i = 0;i < n;i++){
		cout << i + 1 << " " << start[i] << " " << endt[i] << endl;
	}
	return 0;
}