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++: 


/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

vector<vector<int>> graph(101);

vi d(101, -INF), f(101);

int cur = 0;

void dfs(int s){
  d[s] = ++cur;
  for (auto next : graph[s]) {
    if (d[next] != -INF) continue;
    dfs(next);
  }
  f[s] = ++cur;
}

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

  int n; cin >> n;
  graph.resize(n); d.resize(n); f.resize(n);

  rep(i, n) {
    int u, k; cin >> u >> k;
    --u;
    rep(j, k) {
      int v; cin >> v; --v;
      graph[u].push_back(v);
    }
  }
  dfs(0);

  for (int i = 0; i < n; ++i) {
    if (d[i] == -INF) dfs(i);
    cout << i + 1 << " " << d[i] << " " << f[i] << '\n';
  }

  return 0;
}

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

using namespace std;

const int MAX = 101;

vector<int> G[MAX];
int d[MAX], f[MAX];
int *T;

void dfs(int u) {

    if (!d[u]) d[u] = ++(*T);

    for (int v : G[u]) {
        if (!d[v]) {
            d[v] = ++(*T);
            dfs(v);
        }
    }

    if (!f[u]) f[u] = ++(*T);
}

int main() {

    int n;
    cin >> n;

    int t = 0;
    T = &t;
    fill(d, d + MAX, 0);
    fill(f, f + MAX, 0);

    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);
        }
    }

    for (int i = 1; i <= n; i++) {
        if (!d[i]) dfs(i);
    }


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

C++: #include <bits/stdc++.h>
using namespace std;
#define N 100
int t = 0;
stack<int> st;
int d[N + 1], f[N + 1], V[N + 1];
int adj[N + 1][N + 1];

void dfs(int i, int n)
{
    for (int j = 0; j < V[i]; j++)
    {
        if (d[adj[i][j]] == -1)
        {
            d[adj[i][j]] = ++t;
            dfs(adj[i][j], n);
        }
    }
    f[i] = ++t;
}

int main()
{
    int n;
    cin >> n;
    V[0] = n;
    for (int i = 0; i < n; i++)
        adj[0][i] = i + 1;
    for (int i = 0; i < n; i++)
    {
        int u, k;
        cin >> u >> k;
        V[u] = k;
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            adj[u][j] = v;
        }
    }

    for (int i = 0; i <= n; i++)
        d[i] = f[i] = -1;

    dfs(0, n);

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

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

using namespace std;

#define MAX 110
int num;
int matrix[MAX][MAX];
int dst[MAX];

void input(){
    cin >> num;
    for(int i=0;i<MAX;i++){
        dst[i] = -1;
        for(int j=0;j<MAX;j++){
            matrix[i][j] = 0;
        }
    }
    for(int i=1;i<=num;i++){
        int v; cin >> v;
        int tmp; cin >>tmp;
        for(int j=0;j<tmp;j++){
            int vi; cin >> vi;
            matrix[v-1][vi-1] = 1;
        }
    }
}

void dfs(){
    stack<int> S;
    S.push(0);
    dst[0] = 0;
    while(!S.empty()){
        int cur = S.top();
        S.pop();
        if(dst[cur]==-1 || dst[cur]== 0){
            for(int i=0;i<num;i++){
                if(matrix[cur][i]==1){
                    S.push(i);
                    dst[i] = dst[cur] + 1;
                }
            }
        }
        else{
            for(int i=0;i<num;i++){
                if(matrix[cur][i]==1){
                    if(dst[cur] +1 <= dst[i]){
                        S.push(i);
                        dst[i] = dst[cur] + 1;
                    }
                }
            }
        }
    }
    for(int i=0;i<num;i++){
        cout << i+1 << " " <<  dst[i] << endl;
    }
}

int main(){
    input();
    dfs();
}