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> 
#include <stack>
using namespace std;

static const int M_NUM = 100;
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;

int adj_M[M_NUM][M_NUM];
int v_num, Time(0);
int visit_state[M_NUM], D_time[M_NUM], C_time[M_NUM];

void DepthFirstSearch_Recursion(int vertex) 
{
    visit_state[vertex] = GRAY;
    D_time[vertex] = ++Time;
    for (int i = 0; i < v_num; ++i)
    {
        if (adj_M[vertex][i] && visit_state[i] == WHITE) DepthFirstSearch_Recursion(i);
    }
    visit_state[vertex] = BLACK;
    C_time[vertex] = ++Time;
}

int main() 
{
    int v_id, v_degree, adj_v;
    cin >> v_num;

    for (int i = 0; i < v_num; ++i) 
    {
        for (int j = 0; j < v_num; ++j) 
        {
            adj_M[i][j] = 0;
        }
    }

    for (int i = 0; i < v_num; ++i) 
    {
        cin >> v_id >> v_degree;
        v_id--;
        for (int j = 0; j < v_degree; ++j) 
        {
            cin >> adj_v;
            adj_v--;
            adj_M[v_id][adj_v] = 1;
        }
    }

    for (int i = 0; i < v_num; ++i) visit_state[i] = WHITE;

    for (int i = 0; i < v_num; ++i) if (visit_state[i] == WHITE) DepthFirstSearch_Recursion(i);

    for (int i = 0; i < v_num; ++i) 
    {
        cout << i + 1 << " " << D_time[i] << " " << C_time[i] << endl;
    }
}

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

vector<vector<int> > v;
vector<int> d,f,visited;
int cnt = 0;

void dfs(int node, vector<vector<int> > &graph)
{
  //cout << node+1 << " " << cnt+1 << "\n";
  d[node] = cnt;
  cnt++;
  visited[node] = 1;
  for(int i = 0; i<v[node].size(); i++)
  {
    if(visited[v[node][i]] == 1) continue;
    dfs(v[node][i], v);
  }
  //visited[node] = 0;
  //cout << node+1 << " " << cnt+1 << "\n";
  f[node] = cnt;
  cnt++;
}

int main()
{
  int n; cin>>n;
  d.resize(n, 0);
  f.resize(n, 0);
  visited.resize(n, 0);
  v.resize(n);
  for(int i=0; i<n; i++)
  {
    int id, u; cin>>id>>u;
    id--;
    v[i].resize(u);
    for(int j=0; j<u; j++)
    {
      int l; cin>>l;
      l--;
      v[id][j] = l;
    }
  }
  for(int i = 0; i < n; i++)
  {
    if (visited[i]) continue;
    else dfs(i, v);
  }
  for(int i = 0; i<n; i++)
  {
    cout << i+1 << " " << d[i] + 1 << " " << f[i] + 1 << "\n";
  }
  return 0;
}

C++: #include<iostream>
#include<stack>

using namespace std;

int  n, M[100][100], d[100], f[100], color[100], tt, nt[100], W = 0, G = 1, B = 2;

int next (int u) {

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

}

void dfs_visit (int r) {

    int i, u, v;

    for (i = 0; i < n; i++) {
        nt[i] = 0;
    }

    stack<int> S;
    S.push(r);
    color[r] = G;
    d[r] = ++tt;

    while (!S.empty()) {
        u = S.top();
        v = next (u);
        if (v != -1) {
            if (color[v] == W) {
                color[v] = G;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = B;
            f[u] = ++tt;
        }
    }

}

void dfs () {

    int i, u;

    for (i = 0; i < n; i++) {
        color[i] = W;
        nt[i] = 0;
    }
    tt = 0;

    for (u = 0; u < n; u++) {
        if (color[u] == W) {
            dfs_visit(u);
        }
    }

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

}

int main () {

    int u, k, v, i, j;

    cin >> n;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }

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

    dfs ();

    return 0;

}

C++: #include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;
const ll MOD = 998244353;

int t = 1, k[100], v[100][100], d[100], f[100];

void dfs(int x) {
    d[x] = t;
    t++;
    rep(i, k[x]) {
        int y = v[x][i];
        if (d[y] > 0) continue;
        dfs(y);
    }
    f[x] = t;
    t++;
}

int main() {
    int n, u;
    cin >> n;
    rep(i, n) {
        cin >> u;
        cin >> k[u - 1];
        rep(j, k[u - 1]) {
            cin >> v[u - 1][j];
            v[u - 1][j]--;
        }
    }
    rep(i, n) d[i] = 0;
    rep(i, n) if (d[i] == 0) dfs(i);
    rep(i, n) {
        cout << i + 1 << " " << d[i] << " " << f[i] << "\n";
    }
}

C++: #include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 105;
const int INF = 1000;

vector<int> to[MAX_N];
int d[MAX_N], f[MAX_N]; // d：発見時刻、f：完了時刻
int t = 0; int n; 

void init(){
    rep(i,MAX_N){
        d[i] = INF, f[i] = INF;
    }
}

void dfs(int u){
    if(d[u] == INF) d[u] = ++t;
    for(auto v: to[u]){
        if(d[v] == INF) dfs(v); // *もう訪問が完了している頂点には不要に寄らない
    }
    if(f[u] == INF) f[u] = ++t;
}

void dfs_init(){
    rep(i,n){
        if(d[i] == INF) dfs(i);
    }
}

int main()
{
    cin >> n;
    init();
    rep(i,n){
        int u, k; cin >> u >> k; --u;
        rep(_,k){
            int v; cin >> v; --v;
            to[u].push_back(v);
        }
    }
    dfs_init();
    rep(i,n){
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
}