Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------
class Graph{

public:
  vector<vector<int> > graphs;
  vector<bool> check; // For DFS
  vector<ll> dist;   // For BFS
  queue<int> q; // For BFS

  vector<int> d;
  vector<int> f;
  int t;

  Graph(int n){
    graphs.resize(n);
    init(n);
  }
  ~Graph(){}

  void addedge(int u, int v){
    u--; v--;
    graphs[u].push_back(v);
    graphs[v].push_back(u);
  }

  void addedge_cin(int m){
    rep(i,m){
      int a, b;
      cin >> a >> b;
      addedge(a, b);
    }
  }

  void init(int n){
    check.resize(n, false);
    dist.resize(n, -1);
    d.resize(n, -1);
    f.resize(n, -1);
  }

  void reset(){
    rep(i,check.size()){
      check[i]=false;
      dist[i]=-1;
    }
  }

  void dfs(int v)
  {
    t++;
    check[v] = true;
    d[v] = t;

    for(int next_v : graphs[v]){
      if(check[next_v]) continue;
      dfs(next_v);
    }
    t++;
    f[v] = t;
  }

  void bfs(int v)//----------------------
  {
    dist[v] = 0;
    q.push(v);

    while(!q.empty()){
      int cur_v = q.front();
      q.pop();

      for(int next_v : graphs[cur_v]){
        if(dist[next_v] != -1){
          continue;
        }

        dist[next_v] = dist[cur_v] + 1;
        q.push(next_v);
      }
    }
  }//-----------------------

};

int main(void) {
  int n;
  cin >> n;
  Graph g(n);

  rep(i,n){
    int vertex, num;
    cin >> vertex >> num;
    vertex--;
    if(num==0) continue;
    rep(j,num){
      int tmp;
      cin >> tmp;
      tmp--;
      g.graphs[vertex].pb(tmp);
    }
    sortall(g.graphs[vertex]);
  }

  g.t = 0;
  rep(i,n){
    if(!g.check[i]){
      g.dfs(i);
    }
  }

  rep(i,n){
    prt3(i+1, g.d[i], g.f[i]);
  }
}

C++: #include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include  <cassert>
#include <fstream>
#include <codecvt>

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define int ll
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


static const int N = 100;
int G[N][N],d[N],f[N], tt;

#define WHITE 0
#define GRAY 1
#define BLACK 2

int color[N];

void  dfs(int u) {
	color[u] = GRAY;
	d[u] = ++tt;
	rep(v, N) {
		if (G[u][v] and color[v] == WHITE) {
			dfs(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

signed main() {
	ios::sync_with_stdio(true);

	rep(i, N) {
		color[i] = WHITE;
		rep(j, N)
			G[i][j] = 0;
	}

	int n;
	cin >> n;
	rep(i, n) {
		int u, k;
		cin >> u >> k;
		u--;
		rep(j, k) {
			int v;
			cin >> v;
			G[u][--v] = 1;
		}
	}

	tt = 0;
	rep(u, n) {
		if (color[u] == WHITE)
			dfs(u);
	}
	rep(u, n) {
		cout << u + 1 << ' ' << d[u] << ' ' << f[u] << endl;
	}
	return 0;
}

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

using namespace std;

enum COLOR {
  WHITE,
  GRAY,
  BLACK,
};

static const int NIL = -1;
static const int N = 100;

static int M[N][N] = {};

static inline int next(int u, int next_array[]) {
  for (int v = 0; v < next_array[u]; v++) {
    next_array[u] = v + 1;
    if (M[u][v]) {
      return v;
    }
  }
  return NIL;
}

static vector<int> u(N, 0);
static vector<COLOR> color(N, WHITE);
static vector<int> visit_time(N, 0), finish_time(N, 0);

void dfs_visit(int r) {
  vector<int> next_array(N, NIL);

  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  int total_time = 0;
  visit_time[r] = ++total_time;

  while (!S.empty()) {
    int u = S.top();
    int v = next(u, &next_array[0]);
    if (v != NIL) {
      if (color[v] == WHITE) {
        color[v] = GRAY;
        visit_time[v] = ++total_time;
        S.push(v);
      }
    } else {
      S.pop();
      color[u] = BLACK;
      finish_time[u] = ++total_time;
    }
  }
}

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

int main() {
  int n;
  cin >> n;

  int number, count, value;
  for (int i = 0; i < n; i++) {
    cin >> number >> count;
    number--;
    for (int j = 0; j < count; j++) {
     cin >> value;
     value--;
     M[number][value] = 1; 
    }
  }
  
  dfs(n);

  return 0;
}