Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		u, k := sc.nextInt()-1, sc.nextInt()
		for j := 0; j < k; j++ {
			G[u] = append(G[u], sc.nextInt()-1)
		}
	}
	ans := make([][2]int, N)
	time := 0
	found := make(map[int]bool)
	var dfs func(cur int)
	dfs = func(cur int) {
		time++
		ans[cur][0] = time
		found[cur] = true
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !found[next] {
				dfs(G[cur][i])
			}
		}
		time++
		ans[cur][1] = time
	}
	for i := 0; i < N; i++ {
		if !found[i] {
			dfs(i)
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprint(wtr, i+1)
		for j := 0; j < 2; j++ {
			fmt.Fprint(wtr, " ")
			fmt.Fprint(wtr, ans[i][j])
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}

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

struct StSeq
{
  int m_nBgn;
  int m_nEnd;

  StSeq() : m_nBgn(0), m_nEnd(0)
  { }
};

void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StSeq>& rvoDFSrch)
{
  int nxSiz;
  cin >> nxSiz;

  rvvnAdjcy.resize(nxSiz + 1, vector<int>(nxSiz + 1, 0));
  for (int i = 0; i < nxSiz; ++i)
  {
    int nx, nySiz;
    cin >> nx >> nySiz;
    for (int j = 0; j < nySiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
  StSeq oSeq;
  rvoDFSrch.resize(nxSiz + 1, oSeq);
}

void fnDepthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy, vector<StSeq>& rvoDFSrch, int nx)
{
  static int stnCnt = 0;

  if (rvoDFSrch[nx].m_nBgn)  return;
  rvoDFSrch[nx].m_nBgn = ++stnCnt;

  for (int ny = 1; ny < cnrvvnAdjcy.size(); ++ny)
    if (cnrvvnAdjcy[nx][ny] == 1  &&
        nx != ny                )
      fnDepthFirstSearch(cnrvvnAdjcy, rvoDFSrch, ny);

  rvoDFSrch[nx].m_nEnd = ++stnCnt;
}

void fnResult(const vector<StSeq>& cnrvoDFSrch)
{
  for (int i = 1; i < cnrvoDFSrch.size(); ++i)
    cout << i <<  " " << cnrvoDFSrch[i].m_nBgn << " " << cnrvoDFSrch[i].m_nEnd << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;
  vector<StSeq> voDFSrch;

  fnInput(vvnAdjcy, voDFSrch);
  for (int nx = 1; nx < voDFSrch.size(); ++nx)
    fnDepthFirstSearch(vvnAdjcy, voDFSrch, nx);
  fnResult(voDFSrch);

  return 0;
}

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

using namespace std;

struct vertex {
    bool visited;
    int d;
    int f;

    vertex() : visited(false), d(0), f(0) {}
};

int current_time = 1;

void dfs(vector<vector<int>>& g, vector<vertex>& info, int index) {
    if (info[index].visited)
        return;

    info[index].d = current_time;
    info[index].visited = true;
    ++current_time;

    for (int i = 0; i < g[index].size(); ++i)
        dfs(g, info, g[index][i]);
    info[index].f = current_time;
    ++current_time;
}

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

    vector<vector<int>> g(n + 1);
    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].push_back(v);
        }
    }

    vector<vertex> result_info(n + 1);
    for (int i = 1; i <= n; ++i) {
        if (!result_info[i].visited)
            dfs(g, result_info, i);
    }

    for (int i = 1; i <= n; ++i)
        cout << i << ' ' << result_info[i].d << ' ' << result_info[i].f << '\n';
}

C++: #include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int t;
vector< vector<int> > A;
vector<int> c;
vector<int> d;
vector<int> f;

void dfsVisit(int u) {
    t++;
    d[u] = t;
    c[u] = 1;
    for(int i=0; i<A[u].size(); i++) {
        int v = A[u][i];
        if(c[v] == 0) dfsVisit(v);
    }
    t++;
    f[u] = t;
}

void dfs() {
    for(int u=0; u<n; u++) c[u] = 0;
    t = 0;
    for(int u=0; u<n; u++) {
        if(c[u] == 0) {
            dfsVisit(u);
        }
    }
}

int main() {
    cin >> n;
    A.resize(n);
    c.resize(n);
    d.resize(n);
    f.resize(n);

    for(int i=0; i<n; i++) {
        int u,k;
        cin >> u >> k;
        A[u-1].resize(k);
        for(int j=0; j<k; j++) {
            int v;
            cin >> v;
            A[u-1][j] = v-1;
        }
        sort(A[u-1].begin(), A[u-1].end());
    }

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

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

int V;
Graph G;
vector<int> d;
vector<int> f;
vector<int> color;

#define WHITE 0
#define GRAY 1
#define BLACK 2

int now;

void dfs(const Graph &G, int v){
    color[v] = GRAY;
    d[v] = ++now;
    for(auto nv : G[v]){
        if(color[nv]==WHITE){
            dfs(G, nv);
        }
    }
    color[v] = BLACK;
    f[v] = ++now;
}

int main()
{
    now = 0;
    cin >> V;
    G.resize(V);
    d.assign(V, -1);
    f.assign(V, -1);
    color.assign(V, 0);
    rep(j, V)
    {
        int from;
        cin >> from;
        --from;
        int k;
        cin >> k;
        rep(i,k){
            int to;
            cin >> to;
            --to;
            G[from].push_back(to);
        }
    }
    for (int i = 0; i < V; i++){
        if(color[i] == WHITE)
            dfs(G, i);
    }

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

C++: #include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

vector<UL> E[100];
UL ans[100][2]={};
UL tp=0;
bool F[100]={};

void DFS(UL p){
 F[p]=true;
 tp++; ans[p][0]=tp;
 for(UL e:E[p]){
  if(F[e]) continue;
  DFS(e);
 }
 tp++; ans[p][1]=tp;
}

int main() {
 UL N; scanf("%u",&N);
 rep(i,N){
  UL v; scanf("%u",&v); v--;
  UL c; scanf("%u",&c);
  rep(i,c){
   UL e; scanf("%u",&e); e--;
   E[v].push_back(e);
  }
 }
 rep(i,N) if(!F[i]) DFS(i);
 rep(i,N) printf("%u %u %u\n",i+1,ans[i][0],ans[i][1]);
 return 0;
}