Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <complex>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int d[110], f[110];
vector<int> g[110];
int t;
bool used[110];
void solve(int i, int b) {
    if (used[i]) return;
    used[i] = true;
    t++;
    d[i] = t;
    for (int j: g[i]) {
        if (j == b) continue;
        solve(j, i);
    }
    t++;
    f[i] = t;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int id, u;
        cin >> id >> u;
        for (int j = 0; j < u; j++) {
            int a;
            cin >> a;
            g[id].push_back(a-1);
        }
    }
    t = 0;
    fill_n(used, 110, false);
    solve(0, -1);
    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<ll> d, f;

void dfs(Graph &graph, ll u, ll pre, ll &c) {
    d[u] = c;
    c++;
    sort(graph[u].begin(), graph[u].end());
    for (ll v : graph[u]) {
        if (d[v] == 0) {
            dfs(graph, v, u, c);
            c++;
        }
    }
    f[u] = c;
}

void Main() {
    ll N;
    cin >> N;
    Graph graph(N);
    d.assign(N, 0);
    f.assign(N, 0);
    rep(i, N) {
        ll u, k;
        cin >> u >> k;
        u--;
        rep(j, k) {
            ll v;
            cin >> v;
            v--;
            graph[u].push_back(v);
        }
    }
    ll v = 1;
    rep(i, N) {
        if (d[i] == 0) {
            dfs(graph, i, -1, v);
            v++;
        }
    }
    rep(i, N) {
        cout << i + 1 << ' ';
        cout << d[i] << ' ';
        cout << f[i] << '\n';
    }
}

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

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

int n, t = 0;
int A[101][101];
int d[101], f[101];

void dfs(int r) {
	d[r] = ++t;
	for (int i = 1; i <= n; i++) {
		if (A[r][i] == 1 && d[i] == 0) dfs(i);
	}
	f[r] = ++t;
	return;
}

int main() {
	int u, v, l;
	cin >> n;

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

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			A[i][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++) {
		cin >> u >> l;
		for (int j = 0; j < l; j++) {
			cin >> v;
			A[u][v] = 1;
		}
	}

	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 <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <utility>
#include <climits>
#include <cstring>
#include <cstdio>

using namespace std;
typedef long long int llg;

const int INF = 1000001000;
#define REP(var, count) for(int var=0; var<count; var++)

template <typename T>
using reverse_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	std::fill( (T*)array, (T*)(array+N), val );
}

vector<int> rin[105];
pair<int, int> res[105];

int dfs(int a, int time) {
	res[a].first = time;
	for ( int r : rin[a] ) {
		if ( res[r].first != -1 ) { continue; }
		time = dfs(r, time + 1);
	}
	res[a].second = time + 1;
	return res[a].second;
}

int main(void) {
	int N;
	cin >> N;
	
	for(int i=1; i<=N; i++) {
		rin[0].push_back(i);
	
		res[i].first = -1;
		res[i].second = -1;
		
		int U, K;
		cin >> U >> K;
		REP(j, K) {
			int x;
			cin >> x;
			rin[U].push_back(x);
		}
	}
	
	dfs(0, 0);
	
	for(int i=1; i<=N; i++) {
		printf("%d %d %d\n", i, res[i].first, res[i].second);
	}
}

C++: #include <iostream>
#include <stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u) {
  for (int v = nt[u]; v < n; ++v){
    nt[u] = v + 1;
    if (M[u][v]) return v;
  }
  return -1;
}

void dfs_visit(int r) {
  for (int i = 0; i < n; ++i) nt[i] = 0;

  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  d[r] = ++tt;

  while( !S.empty()) {
    int u = S.top();
    int v = next(u);
    if (v != -1) {
      if (color[v] == WHITE) {
        color[v] = GRAY;
        d[v] = ++tt;
        S.push(v);
      }
    }
    else {
      S.pop();
      color[u] = BLACK;
      f[u] = ++tt;
    }
  }
}

void dfs() {
  for (int i = 0; i < n; ++i) {
    color[i] = WHITE;
    nt[i] = 0;
  }
  tt = 0;

  for (int u = 0; u < n; u++) {
    if (color[u] == WHITE) dfs_visit(u);
  }
  for (int i = 0; i < n; ++i) {
    cout << i + 1 << " " << d[i] << " " << f[i] << endl;
  }
}

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

  for (int i = 0; i < n; ++i) {
    cin >> u >> k; u--;
    for (int j = 0; j < k; ++j) {
      cin >> v; v--;
      M[u][v] = 1;
    }
  }
  dfs();
  return 0;
}