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 <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

vector<pair<int, int> > ans;
vector<vector<int> > v;
int d = 1;

void dfs(int pos)
{
  ans[pos].first = d++;
  rep(i, v[pos].size())
  {
    int next = v[pos][i];
    if (ans[next].first == -1)
    {
      dfs(next);
    }
  }
  ans[pos].second = d++;
}

int main()
{
  int n;
  cin >> n;
  ans.resize(n);
  v.resize(n);
  rep(i, n)
  {
    ans[i] = make_pair(-1, -1);
    int u, k;
    cin >> u >> k;
    u--;
    v[u].resize(k);
    rep(j, k)
    {
      cin >> v[u][j];
      v[u][j]--;
    }
  }

  rep(i, n)
  {
    if(ans[i].first == -1)
      dfs(i);
  }
  rep(i, n)
  {
    cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <map>
#include <cmath>
#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]; //それぞれの頂点でどの値まで調べたか格納（毎回ゼロから探さなくて良くなり速度向上）

//uに隣接するvを順番に取得
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;

    //未訪問のuを始点として深さ優先探索
    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] <<"\n";
    }

}

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

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int main() {
    int N; cin >> N;
    vector<vector<int>> G(N);
    rep(i, 0, N) {
        int u, k;
        cin >> u >> k;
        u--;
        rep(j, 0, k) {
            int v; cin >> v;
            v--;
            G[u].push_back(v);
        }
    }
    vector<int> d(N), f(N), visited(N);
    int cnt = 0;
    function<void(int)> dfs = [&](int cur) {
        if(visited[cur]) return;
        d[cur] = ++cnt;
        visited[cur] = 1;
        for(auto &to : G[cur]) {
            if(visited[to]) continue;
            dfs(to);
        }
        f[cur] = ++cnt;
    };
    rep(i, 0, N) dfs(i);
    rep(i, 0, N) cout << i + 1 << " " << d[i] << " " << f[i] << '\n';
    return 0;
}

C++: #include <iostream>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;


int n,m[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
	int v;
	color[u]=GRAY;
	d[u] = ++tt;
	for(v=0;v<n;v++){
		if(m[u][v]&&color[v]==WHITE)
		dfs_visit(v);
	}
	color[u] = BLACK;
	f[u] = ++tt;
	
}

void dfs(){
	int u;
	
	for(u=0;u<n;u++){
		color[u]=WHITE;
	}
	tt=0;
	for(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;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

ll cnt = 0;
vector<pair<ll, ll>> ans;
vector<bool> visited;
void f(ll node, vector<vector<ll>> &graph) {
  if (visited[node]) return;
  visited[node] = true;

  ll found = ++cnt;
  for(ll nxt: graph[node]) {
    f(nxt, graph);
  }
  ll solve = ++cnt;
  ans[node] = {found, solve};
}

int main() {
  ll input(n);
  vector<vector<ll>> graph(n);
  ans = vector<pair<ll, ll>>(n);
  visited = vector<bool>(n);
  REP(i, n) {
    ll input(u, k);
    REP(j, k) {
      ll input(v);
      graph[u - 1].push_back(v - 1);
    }
  }

  REP(i, n) f(i, graph);
  REP(i, n) {
    cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
  }
}