Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
vint G[100];
int FLG[100];
int D[100];
int F[100];
const int NIL = -1;
int tt;

void dfs(int ii){

	tt++;
	D[ii] = tt;

	// cout << "reach " << ii << " " << tt << endl;

	rep(i, G[ii].size()){
		int to = G[ii][i];
		if (D[to] == NIL){
			dfs(to);
		}
	}

	tt++;
	F[ii] = tt;
	// cout << "back " << ii << " " << tt << endl;

}

void run_dfs(){
	rep(i, N){ D[i] = NIL; }
	int start = 0;
	tt = 0;
	rep(i, N){
		if (D[i] == NIL) dfs(start);
	}
}

int main() {

	cin >> N;
	rep(i, N){
		int id, n; cin >> id >> n; id--;
		rep(j, n){
			int id_to; cin >> id_to; id_to--;
			G[id].push_back(id_to);
		}
	}

	run_dfs();

	rep(i, N){
		cout << i << " " << D[i] << " " << F[i] << endl;
	}
}

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

int G[MAX_N][MAX_N];
int status[MAX_N];
int d[MAX_N];
int f[MAX_N];
int time_count, n;

void dfs_visit(int v) {
  d[v] = ++time_count;
  status[v] = GRAY;
  for (int i = 1; i <= n; i++) {
    if (G[v][i] && status[i] == WHITE) dfs_visit(i);
  }

  f[v] = ++time_count;
  status[v] = BLACK;
}

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

  time_count = 0;
  int i;
  for (i = 1; i <= n; i++) {
    if (status[i] == WHITE) {
      dfs_visit(i);
    }
  }
}

void init() {
  for (int i = 0; i < MAX_N; i++) {
    for (int j = 0; j < MAX_N; j++) {
      G[i][j] = 0;
    }
  }
}

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

  dfs();

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

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

using namespace std;

vector<int> adja[101];
int d[101], f[101], cnt;

void dfs(int u) {
    d[u] = ++cnt;
    for (auto v : adja[u]) {
        if (d[v] > 0)
            continue;
        dfs(v);
    }
    f[u] = ++cnt;
}

int main() {
    int n, k, u;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        adja[u].resize(k);
        for (int j = 0; j < k; ++j) {
            cin >> adja[u][j];
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (d[i] == 0)
            dfs(i);
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

void dfs(int start_node_id, vector<vector<int>>& g, vector<int>& visit_status,
         vector<int>& first_visit, vector<int>& last_visit, int& time) {
  visit_status[start_node_id] = 1;
  first_visit[start_node_id] = ++time;
  for (int i = 0; i < (int)g[start_node_id].size(); i++) {
    int node_id = g[start_node_id][i];
    if (visit_status[node_id] == 0) {
      dfs(node_id, g, visit_status, first_visit, last_visit, time);
    }
  }
  visit_status[start_node_id] = 2;
  last_visit[start_node_id] = ++time;
}

int main() {
  int n, k, u, v;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v;
      g[i].push_back(v - 1);
      // g[v - 1].push_back(i);
    }
  }
  debug(g);
  vector<int> visit_status(n), first_visit(n), last_visit(n);
  int time = 0;
  for (int i = 0; i < n; i++) {
    if (visit_status[i] == 0) {
      dfs(i, g, visit_status, first_visit, last_visit, time);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i + 1 << ' ' << first_visit[i] << ' ' << last_visit[i] << endl;
  }
  return 0;
}