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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;
vector<int> v[101];
int d[101] = {0};
int f[101] = {0};
int t = 0;
void dfs(int id) {
    //d mark
    d[id] = t;
    t++;
    for(int adj: v[id]) {
        if(d[adj] == 0) {
            dfs(adj);
            t++;
        }
    }
    f[id] = t;
}

int main() {
    int n;
    cin >> n;
    for(int i=1; i<=n; i++) {
        int u, k;
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            int adj;
            cin >> adj;
            v[i].push_back(adj);
        }
    }
    for(int i=1; i<=n; i++) {
        if(d[i] == 0) {
            t++;
            dfs(i);
        }
    }

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

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

using Graph = vector<vector<int>>;

int dfs(Graph &graph, vector<int> &d, vector<int> &f, int cur, int time)
{
    if(d[cur] > 0) return time;
    d[cur] = time;
    time++;
    for(int child : graph[cur])
    {
        time = dfs(graph, d, f, child, time);
    }
    f[cur] = time;
    time++;
    return time;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    Graph graph(n);
    REP(i, n) 
    {
        int u, k;
        cin >> u >> k;
        REP(j, k) 
        {
            int v;
            cin >> v;
            graph[u-1].push_back(v-1);
        }
    }

    vector<int> d(n, 0), f(n, 0);
    int time = 1;
    REP(i, n)
    {
        if(d[i] > 0) continue;
        time = dfs(graph, d, f, i, time);
    }

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

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

int G[101][102];
int found[101];
int comp[101];   // complete.
int t;  // time.

typedef struct box{ int val; box* next; } box_t;  // stack.

box_t* init()
{
    box_t* head = new box_t;
    head->val = -1;
    head->next = NULL;
    return head;
}

bool isEmpty(box_t* head){ return (head->next == NULL ? true : false); }

box_t* push(box_t* head, int data)
{
    box_t* box = new box_t;
    box->val = data;
    box->next = head->next;
    head->next = box;
    return box;
}

int pop(box_t* head)
{
    if(isEmpty(head)){ return -1; }
    box_t* box = head->next;
    int val;
    head->next = box->next;
    val = box->val;
    delete box;
    return val;
}

int front(box_t* head)
{
    int val;
    if(isEmpty(head)){ return -1; }
    val = head->next->val;
    return val;
}

box_t* stack = init();

void search_loop(int i)
{
    int j, k;
    while(1){
        if(found[i] == 0){
            t++; found[i] = t;
            push(stack, i);
        }
        for(k = G[i][0]; G[i][k] != 0 && found[G[i][k]] != 0; k++);
        if(G[i][k] == 0){
            if(isEmpty(stack)){ return; }
            else{
                j = pop(stack);
                t++; comp[j] = t;
                i = front(stack);
            }
        }else{
            G[i][0] = k + 1;
            i = G[i][k];
        }
    };
    return;
}

int main()
{
    int n, i, j, a, b, e;
    cin >> n;
    for(i = 1; i <= n; i++){
        G[i][0] = 1;
        for(j = 1; j <= n + 1; j++){ G[i][j] = 0; } }

    for(i = 1; i <= n; i++){
        cin >> a >> e;
        for(j = 1; j <= e; j++){
            cin >> b; G[a][j] = b; } }  // adjacent representation.

    for(i = 1; i <= n; i++){ found[i] = 0; comp[i] = 0; }
    t = 0;
    while(1){
        for(i = 1; i <= n; i++){
            if(found[i] == 0) break;
        }
        if(i > n) break;
        search_loop(i);
    };

    for(i = 1; i <= n; i++){
        cout << i << " " << found[i] << " " << comp[i] << endl;
    }
    return 0;
}

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

struct Graph{
	
	vector<char> seen;
	vector<vector<int>> e;
	vector<int> time1,time2; 
	Graph(int n) : seen(n),e(n),time1(n),time2(n){}
	
	void dfs(int v, int &t){
		t++;
		time1.at(v) = t;
		seen.at(v) = 1;
		for(auto nv:e.at(v)) {
			if(seen.at(nv)==1) continue;
			dfs(nv,t);
		}
		t++;
		time2.at(v) = t;
		return;
	}
	
};

int main() {
	
	int n;
	cin >> n;
	Graph graph(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;
			v--;
			graph.e.at(i).push_back(v);
		}
	}
	
	int t={};
	for(int i=0; i<n; i++){
		if(graph.seen.at(i)!=1) graph.dfs(i,t);
	}
	
	for(int i=0; i<n; i++){
		cout << i+1 << ' ' << graph.time1.at(i) << ' ' << graph.time2.at(i) << endl;
	}
	
	
}