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 <bits/stdc++.h>

using namespace std;

#define ll long long
typedef complex<double> P;

int main() {
  int n; cin >> n;
  int adj[n][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;
      adj[u-1][v-1] = 1;
    }
  }

  int d[n] = {};
  int f[n] = {};
  int t = 1;

  stack<int> st;
  st.push(0);

  while (!st.empty()) {
    int v = st.top();

    if(d[v] == 0) {
      d[v] = t;
    }

    for (int i = 0; i < n; i++) {
      if(adj[v][i] == 1 && d[i] == 0) {
        st.push(i);
        break;
      }
    }

    if(st.top() == v) {
      f[v] = t+1;
      st.pop();
    }

    if(st.empty()) {
      t++;
      for (int i = 0; i < n; i++) {
        if(d[i] == 0) {
          st.push(i);
          break;
        }
      }
    }

    t++;
  }

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

}

C++: #include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int n,u,k,p,d[105],f[105],tt=0;
bool adm[105][105],se[105];

void makemap()
{
    memset(adm,false,sizeof(adm));
    memset(se,true,sizeof(se));
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&u,&k);
        while(k--)
        {
            scanf("%d",&p);
            adm[u][p]=true;
        }
    }
}

void dfs(int p)
{
    d[p]=++tt;
    se[p]=false;
    for(int i=1;i<=n;i++)
        if(adm[p][i]&&se[i])dfs(i);
    f[p]=++tt;
}

int main()
{
    makemap();
    for(int i=1;i<=n;i++)if(se[i])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<vector>
#include<queue>

using namespace std;

vector<vector<int>> adjacent;
vector<pair<int, int>> ans;
vector<bool>checked;

//?????????is????????????
int dfs(int now,int time = 1) {
	ans[now].first = time;
	checked[now] = true;
	for (int i = 0; i < adjacent[now].size(); i++) {
		if (!checked[adjacent[now][i]]) {
			time = dfs(adjacent[now][i], time + 1);
		}
	}
	ans[now].second = time+1;
	return time + 1;
}

int main() {
	int n;
	cin >> n;
	adjacent = vector<vector<int>>(n);
	checked = vector<bool>(n, false);
	ans.resize(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;
			adjacent[u - 1].push_back(v-1);
		}
	}
	
	int time = dfs(0, 1)+1;
	for (int i = 0; i < n; i++) {
		if (!checked[i])time = dfs(i, time)+1;
	}
	
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
	}

}

C++: #include "bits/stdc++.h"

using namespace std;

using ll = long long;

constexpr char endl('\n');

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define INF 100000000000ULL

vector<vector<size_t>> g;
vector<size_t> gs;
vector<size_t> gf;
stack<size_t> st;

size_t dfs(size_t i, size_t t) {
	st.push(i);
	while (!st.empty()) {
		auto j = st.top();
		vector<size_t>& l = g.at(j);
		if (gs.at(j) != 0) {
			if (gf.at(j) == 0)
				gf.at(j) = ++t;
			st.pop();
			continue;
		}
		gs.at(j) = ++t;
		for (ll k = l.size() - 1; k >= 0; --k) {
			auto n = l.at(k);
			if (gs.at(n) == 0) {
				st.push(n);
			}
		}
	}
	return t;
}

int main() {
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	size_t n;
	cin >> n;
	g.resize(n);
	gs.resize(n);
	gf.resize(n);

	REP(i, n) {
		size_t u, k;
		cin >> u >> k;
		u -= 1; // 0 base
		g.at(u).resize(k);
		REP(j, k) {
			cin >> g.at(u).at(j);
			g.at(u).at(j)--;
		}
	}
	size_t t = 0;
	for (;;) {
		size_t target = INF;
		REP(i, n) {
			if (gs.at(i) == 0) {
				target = i;
				break;
			}
		}
		if (target == INF) break;
		t = dfs(target, t);
	}
	
	REP(i, n) {
		cout << i + 1 << " " << gs.at(i) << " " << gf.at(i) << ::endl;
	}
	return 0;
}

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

vector<int> graph[100];
int start[100],endt[100];
int cnt;

void dfs(int num){
	start[num] = ++cnt;
	for(int i = 0;i < graph[num].size();i++){
		if(graph[num][i] != num && !start[graph[num][i]] && !endt[graph[num][i]]) dfs(graph[num][i]);
	}
	endt[num] = ++cnt;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int now,m;
		cin >> now >> m;
		for(int j = 0;j < m;j++){
			int t;
			cin >> t;
			graph[now - 1].push_back(t - 1);
		}
	}
	dfs(0);
	for(int i = 0;i < n;i++){
		if(!endt[i]) dfs(i);
	}
	for(int i = 0;i < n;i++){
		cout << i + 1 << " " << start[i] << " " << endt[i] << endl;
	}
	return 0;
}