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 n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
    color[u] = GRAY;
    d[u] = ++tt;
    for (int 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() {
    for (int u=0; u < n; u++) color[u] = WHITE;
    tt = 0;
    for (int u = 0; u < n; u++) {
        if (color[u] == WHITE) dfs_visit(u);
    }
    for (int i = 0; i < n; i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    cin >> 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++) {
        int u, l; cin >> u >> l;
        u--;
        for (int j = 0; j < l; j++) {
            int v; cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();
    
    return 0;
}

C++: #include <vector>
#include <iostream>
using namespace std;
int n, u, k, v, t, d[100][2]; vector<int> g[100];
void rec(int pos) {
	d[pos][0] = ++t;
	for(int i = 0; i < g[pos].size(); i++) {
		if(!d[g[pos][i]][0]) rec(g[pos][i]);
	}
	d[pos][1] = ++t;
}
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
		for(int j = 0; j < k; j++) cin >> v, g[u - 1].push_back(v - 1);
	}
	for(int i = 0; i < n; i++) {
		if(!d[i][0]) rec(i);
	}
	for(int i = 0; i < n; i++) cout << i + 1 << ' ' << d[i][0] << ' ' << d[i][1] << endl;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
vint G[100];
int FLG[100];
int D[100];
int F[100];
const int NIL = -1;
int tt;

void dfs(int ii){

	tt++;
	D[ii] = tt;

	// cout << "reach " << ii << " " << tt << endl;

	rep(i, G[ii].size()){
		int to = G[ii][i];
		if (D[to] == NIL){
			dfs(to);
		}
	}

	tt++;
	F[ii] = tt;
	// cout << "back " << ii << " " << tt << endl;

}

void run_dfs(){
	rep(i, N){ D[i] = NIL; }
	int start = 0;
	tt = 0;
	rep(i, N){
		if (D[i] == NIL) dfs(i);
	}
}

int main() {

	cin >> N;
	rep(i, N){
		int id, n; cin >> id >> n; id--;
		rep(j, n){
			int id_to; cin >> id_to; id_to--;
			G[id].push_back(id_to);
		}
	}

	run_dfs();

	rep(i, N){
		cout << (i+1) << " " << D[i] << " " << F[i] << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#define N 200

using namespace std;
vector<vector<int> > pa;
vector<vector<int> > ch;
int first[N] = {0};
int second[N] = {0};
int timestamp = 0;
void dfs(int x) {
    if (ch[x].empty()) {
        return;
    } else {
        for (int i = 0; i < ch[x].size(); i++) {
            if (first[ch[x][i]] * second[ch[x][i]] == 0) {
                timestamp++;
                first[ch[x][i]] = timestamp;
                dfs(ch[x][i]);
                timestamp++;
                second[ch[x][i]] = timestamp;
            }
        }
        return;
    }
}
int main() {
    int n;
    cin >> n;
    int temp = n;
    pa.clear(); pa.resize(N + 5);
    ch.clear(); ch.resize(N + 5);
    while (temp--) {
        int u, k, v;
        cin >> u >> k;
        for (int i = 0; i < k; i++) {
            cin >> v;
            pa[v].push_back(u);
            ch[u].push_back(v);
        }
    }
    int an = 0;
    for (int i = 1; i <= n; i++) {
        sort(pa[i].begin(), pa[i].end(), less<int>());
        sort(ch[i].begin(), ch[i].end());
        if (pa[i].empty())
            an = i;
    }
    timestamp++;
    first[an] = timestamp;
    dfs(an);
    timestamp++;
    second[an] = timestamp;
    for (int i = 1; i <= n; i++) {
        cout << i << ' ' << first[i] << ' ' << second[i] << '\n';
    }
}

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;
  dfs(0,p);
  for(int i=0;i<n;i++) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;;
  return 0;
}