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<cstdio>
using namespace std;
int k[101]={0},v[101][101]={0};
int d[101]={0},f[101]={0};
int cur=0;
void dfs(int id)
{
	if(d[id]!=0)
	{
		return;
	}
	cur++;
	if(d[id]==0)
	{
		d[id]=cur;
	}
	for(int i=0;i<k[id];i++)
	{
		dfs(v[id][i]);
	}
	cur++;
	f[id]=cur;
	return;
}
int main(void)
{
	int n=0,u=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&u);
		scanf("%d",&k[u]);
		for(int j=0;j<k[u];j++)
		{
			scanf("%d",&v[u][j]);
		}
	}
	for(int i=1;i<n;i++)
	{
		if(d[i]==0)
		{
			dfs(i);
		}
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d %d %d\n",i,d[i],f[i]);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

vector<int>visited;
vector<int>d,f;
int cnt;

void dfs(int v,vector<vector<int>> &g){
  if(!visited[v])visited[v]=1,d[v]=++cnt;
  for(auto x:g[v]){
    if(visited[x]==0){
      dfs(x,g);
    }
  }
  visited[v]=2;
  f[v]=++cnt;
}

void solve(){
  int n;
  cin>>n;
  cnt=0;
  visited.resize(n);
  d.resize(n);f.resize(n);
  vector<vector<int>>g(n);
  rep(i,n){
    int u;
    cin>>u;
    u--;
    int k;
    cin>>k;
    int v;
    rep(j,k){
      cin>>v;
      v--;
      g[u].pb(v);
    }
  }
  rep(i,n){
    if(!visited[i])dfs(i,g);
  }
  rep(i,n){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<"\n";
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define MAX 101

int n;
Graph G(MAX);
vector<bool> seen(MAX, false);
vector<int> d(MAX), f(MAX);
int timer = 1;

void dfs(const Graph &G, int v)
{
  seen.at(v) = true;
  d.at(v) = timer++;
  int next_v;
  for (int i = 0; i < G.at(v).size(); i++)
  {
    next_v = G.at(v).at(i);
    if (seen.at(next_v))
    {
      continue;
    }
    dfs(G, next_v);
  }
  f.at(v) = timer++;
}

int main()
{
  cin >> n;
  int k, u, v;
  for (int i = 0; i < n; i++)
  {
    cin >> u >> k;
    for (int j = 0; j < k; j++)
    {
      cin >> v;
      G.at(u).push_back(v);
    }
  }
  for (int v = 1; v <= n; v++)
  {
    if (seen.at(v))
    {
      continue;
    }
    dfs(G, v);
  }
  for (int i = 1; i <= n; i++)
  {
    cout << i << " " << d.at(i) << " " << f.at(i) << endl;
  }
}

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

using namespace std;

int n;
vector<vector<int>> g; 
int time = 0;
int timeT = 0;
vector<int> d, f;
 
void dfs(int node){
    timeT++;

    if(d[node] == 0){
        d[node] = timeT;
    }

    for(auto next : g[node]){
        if(d[next] == 0){
            dfs(next);
        }
    }
    
    timeT++;
    if(f[node] == 0){
        f[node] = timeT;
    }
    return;
}
    
int main(){
    
    cin >> n;

    d.assign(n + 1, 0);
    f.assign(n + 1, 0);

    g.assign(n + 1, vector<int>());

    for(int i = 0; i < n; i++)
    {
        int nod, numOut;
        cin  >> nod >> numOut;
        for(int j = 0; j < numOut; j++)
        {
            int temp;
            cin >> temp;
            g[nod].push_back(temp);
        }
    }
    
    for(int i = 1; i <= n; i++)
    {
        if(d[i] == 0){
            dfs(i);
        }
    }

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

    return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int t;

void dfs(int pos, vector<int>& d, vector<int>& f, vector<vector<int>>& a){
	d[pos] = t;
	rep(i,a.size()){
		if(a[pos][i] == 1 and d[i] == -1){
			t++;
			d[i] = t;
			dfs(i, d, f, a);
		}
	}
	t++;
	f[pos] = t;
}

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

	vector<vector<int>> a(n, vector<int>(n,0));
	rep(i,n){
		int from;
		int m;
		cin >> from >> m;
		from--;
		rep(j,m){
			int to;
			cin >> to;
			to--;
			a[from][to] = 1;
		}
	}

	vector<int> d(n,-1), f(n);
	t = 1;
	rep(i,n){
		if(d[i] == -1) {
			dfs(i, d, f, a);
			t++;
		}
	}

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