Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	nodes := make(map[int]*node)

	for i := 0; i < num; i++ {
		sc.Scan()
		id, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		nodeNum, _ := strconv.Atoi(sc.Text())
		n := node{id, make([]int, 0), 0, 0}
		for j := 0; j < nodeNum; j++ {
			sc.Scan()
			nid, _ := strconv.Atoi(sc.Text())
			n.nexts = append(n.nexts, nid)
		}
		nodes[id] = &n
	}

	s := Stack{}
	for i := 1; i < len(nodes)+1; i++ {
		if nodes[i].s != 0 {
			continue
		}
		walk(i, &nodes, s)
	}
	for i := 1; i < len(nodes)+1; i++ {
		fmt.Printf("%v %v %v\n", (*nodes[i]).id, (*nodes[i]).s, (*nodes[i]).e)
	}
}

var time int

func walk(nid int, nodes *map[int]*node, s Stack) {
	n := (*nodes)[nid]
	if n.s != 0 {
		return
	}
	time++
	n.s = time
	s.Push(n)
	for _, v := range n.nexts {
		walk(v, nodes, s)
	}
	time++
	n.e = time
}

type node struct {
	id    int
	nexts []int
	s     int
	e     int
}

// Stack is Stack
type Stack struct {
	stack []interface{}
}

// Push new value
func (stack *Stack) Push(val interface{}) {
	stack.stack = append(stack.stack, val)
}

// Pop new value
func (stack *Stack) Pop() interface{} {
	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

int n;
vector<int> first, last;
bool seen[100] = {};

void dfs (const Graph& g, int u, int& ptr) {
    first[u] = ptr++;
    seen[u] = 1;
    for (auto next : g[u]) {
        if (seen[next]) continue;
        dfs (g, next, ptr);
    }
    last[u] = ptr++;
}

int main() {
    cin >> n;
    Graph g (n);
    first.resize (n);
    last.resize (n);
    rep (i, n) {
        int a, k;
        cin >> a >> k;
        rep (j, k) {
            int b;
            cin >> b;
            g[a - 1].push_back (b - 1);
            //g[b].push_back (a);
        }
    }
    int ptr = 0;
    rep (i, n) {
        if (first[i] == 0 && last[i] == 0) {
            dfs (g, i, ptr);
        }
    }

    rep (i, n) cout << i + 1 << " " << first[i] + 1 << " " << last[i] + 1 << "\n";
}