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 <queue>
using namespace std;

int a[101][101];
int n = 0;
int found[101];
int ended[101];
int aaa(int i, int time);

int main() {
  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 101; j++)
	  a[i][j] = 0;
  int u, k, v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
	for (int j = 0; j < k; j++) {
	  cin >> v;
	  a[u][v] = 1;
	  }
	 }
int time = 0;
for (int i = 0; i < 101; i++){
  found[i] = 0;
  ended[i] = 0;
  }
for (int i = 0; i < n+1; i++) {
  if(found[i] > 0)
    continue;
  time++;
  found[i]=time;
  time=aaa(i,time);
  ended[i]=time;
  }
  
for (int i = 1; i < n+1; i++) {
 cout << i << ' ' << found[i] << ' ' << ended[i] << endl;
 }
 
}
 
int aaa(int i, int time) {
  for (int k = 1; k < n+1; k++) {
    if (a[i][k] == 1 && found[k] == 0) {
	  time++;
	  found[k] = time;
	  time = aaa(k,time);
	  ended[k] = time;
	  }
	 }
	time++;
	return time;
	}

C++: #include <iostream>

using namespace std;

int adja[101][101];
int d[101], f[101], cnt;

void dfs(int u) {
    d[u] = ++cnt;
    for (int i = 0, v; (v = adja[u][i]) > 0; ++i) {
        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;
        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;
}