Go: #include <bits/stdc++.h>
using namespace std;
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;
static const int N     = 100;

int n, tt;
vector<vector<int>> M(N, vector<int>(N));
vector<int> color(N), d(N), f(N);

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

void dfs() {
  tt = 0;

  for (int u = 0; u < n; u++) {
    if (color[u] == WHITE) dfs_visit(u);
  }
  for (int u = 0; u < n; u++) {
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}

int main() {
  int u, v, k;
  cin >> n;
  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();
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

bool adj[105][105];
bool vis[105];
struct node{
	int ft;
	int rt;
};
node v[105];

int n;
int cnt;

void dfs (int cur )
{
	cnt++;
	vis[cur] = true;	
	v[cur].ft = cnt;
	for (int u = 1; u <= n; u++ ){
		if (!vis[u] && adj[cur][u] )
			dfs (u );
	} // end for
	cnt++;
	v[cur].rt = cnt;
}

int main()
{
	memset (adj, false, sizeof (adj ) );
	memset (vis, false, sizeof (vis ) );

	ios_base::sync_with_stdio(0);
	cin >> n;

	rep (i, n ) v[i].ft = 0, v[i].rt = 0;

	rep (i, n ){
		int v, k;
		cin >> v >> k;
		while (k-- ){
			int u; cin >> u;
			adj[v][u] = true;
		} // end rep
	} // end rep
	cnt = 0;
	dfs (1 );	

	for (int i = 1; i <= n; i++ ){
		cout << i << ' ' << v[i].ft << ' ' << v[i].rt << endl;
	} // end for
	
	return 0;
}

C++: #include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1000000000;
const int MOD = 1000000007;

typedef pair<int, int> P;
int myAbs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく
int N;
bool E[101][101];
vector<bool> seen;
typedef pair<int, int> P;
int D[101];
int F[101];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[101];
int find_time = 0;

void dfs_search(int u) {
    //出発点を訪問済みにする＆行きのタイムスタンプを記録
    int v;

    color[u] = 1;
    D[u] = ++find_time;
    //cout << u+1 << " " << color[u] << " " << endl;
    for (v = 1; v <= N; v++) {
        //出発点からvへの辺があるか
        if (!E[u][v]) continue;
        //辺がある&&未訪問なら発見した頂点を出発点にして再帰
        if (color[v] == 0) dfs_search(v);
    }
    //今回訪問した頂点より深い未訪問の頂点がない時にその頂点を完了する。
    color[u] = 2;
    F[u] = ++find_time;
}

void dfs() {
    int u;
    find_time = 0;
    for (int i = 0; i < N; i++) color[i] = 0;
    for (u = 1; u <= N; u++) {
        //未訪問のuを出発点にしてDFS
        if (color[u] == 0 || color[u] == 1) dfs_search(u);
    }
    //出力
    for (int i = 1; i <= N; i++) {
        cout << i << " " << D[i] << " " << F[i] << endl;
    }
}

int main() {
    //boolで辺を管理
    cin >> N;
    int u, k;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            E[i][j] = false;
        }
        D[i] = 0;
        F[i] = 0;
    }

    //辺の配列E[][]において、falseは無辺、trueは有辺を表す。
    //有向グラフなのでE[i][j]のみ(無向だとE[j][i]も)
    for (int i = 1; i <= N; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v; cin >> v;
            //v--;
            //u--;
            E[u][v] = true;
        }
    }

    dfs();

}