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>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int V;
Graph G;
vector<int> d;
vector<int> f;
vector<int> color;

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

int now;

void dfs(const Graph &G, int v){
    color[v] = GRAY;
    d[v] = ++now;
    for(auto nv : G[v]){
        if(color[nv]==WHITE){
            dfs(G, nv);
        }
    }
    color[v] = BLACK;
    f[v] = ++now;
}

int main()
{
    now = 0;
    cin >> V;
    G.resize(V);
    d.assign(V, -1);
    f.assign(V, -1);
    color.assign(V, 0);
    rep(j, V)
    {
        int from;
        cin >> from;
        --from;
        int k;
        cin >> k;
        rep(i,k){
            int to;
            cin >> to;
            --to;
            G[from].push_back(to);
        }
    }
    for (int i = 0; i < V; i++){
        if(color[i] == WHITE)
            dfs(G, i);
    }

    for (int i = 0; i < V; i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

vector<UL> E[100];
UL ans[100][2]={};
UL tp=0;
bool F[100]={};

void DFS(UL p){
 F[p]=true;
 tp++; ans[p][0]=tp;
 for(UL e:E[p]){
  if(F[e]) continue;
  DFS(e);
 }
 tp++; ans[p][1]=tp;
}

int main() {
 UL N; scanf("%u",&N);
 rep(i,N){
  UL v; scanf("%u",&v); v--;
  UL c; scanf("%u",&c);
  rep(i,c){
   UL e; scanf("%u",&e); e--;
   E[v].push_back(e);
  }
 }
 rep(i,N) if(!F[i]) DFS(i);
 rep(i,N) printf("%u %u %u\n",i+1,ans[i][0],ans[i][1]);
 return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 100 + 3;
vector<int> g[N];
int time_entry[N];
int time_exit[N];
bool visited[N];
int dfs_timer = 1;

void dfs(int s){
   	visited[s] = true;
    time_entry[s] = dfs_timer++;
   	for(auto it : g[s]){
	  if (!visited[it]) dfs(it);	  	
	}
	time_exit[s] = dfs_timer++;
}
	
int32_t main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) visited[i] = false;
  for(int i = 0; i < n; i++){
	  int m, deg;
	  cin >> m >> deg;
	  m--;
	  for (int i = 0; i < deg; i++){
		  int x;
		  cin >> x;
		  x--;
		  g[m].push_back(x);  
	  }  
   }
  for(int i = 0; i < n; i++){
	    if (!visited[i]) dfs(i);
	}
  for(int i = 0; i < n; i++){
	   int idx = i + 1;
	   cout << idx << " "<< time_entry[i] <<  " "<< time_exit[i] << endl;  
	}     	
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


void dfs(vvi g,int v, int &time,vb &seen,vi &first_time,vi &last_time) {
  first_time[v]=++time;
  seen[v]=true;
  for(auto next_v:g[v]) {
    if(seen[next_v]) continue;
    dfs(g,next_v,time,seen,first_time,last_time);
  }
  last_time[v]=++time;
}

int main() {
  int n;
  cin >> n;
  vvi G(n);
  REP(i,n) {
    int a;
    cin >> a;
    a--;
    int k;
    cin >> k;
    REP(j,k) {
      int b;
      cin >> b;
      b--;
      G[a].push_back(b);
    }
  }
  int time=0;
  vb seen(n,false);
  vi first_time(n,1);
  vi last_time(n,1);
  REP(i,n) {
    if(seen[i]) continue;
    dfs(G,i,time,seen,first_time,last_time);
  }
  REP(i,n) {
    cout << i+1 << " " << first_time[i] << " " << last_time[i] << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <vector>
using namespace std;

int cnt=0;

void DFS(int k, vector<vector<int> >& V, vector<pair<int,int> >& time) {
	time[k].first=cnt++;
	for(int i=1; i<=(int)V[k].size(); ++i) {
		if(time[V[k][i]].first==-1) {
			DFS(V[k][i],V,time);
		}
	}
	time[k].second=cnt++;
	return;
}

int main() {
	int i,j;
	int n;
	int u,k;
	vector<vector<int> > V;
	vector<pair<int,int> > time;
	scanf("%d",&n);
	V.resize(n+1);
	V[0].resize(n+1);
	time.resize(n+1);
	for(i=1; i<=n; ++i) {
		V[0][i]=i;
		scanf("%d%d",&u,&k);
		V[u].resize(k);
		time[u]={-1,-1};
		for(j=1; j<=k; ++j) {
			scanf("%d",&V[u][j]);
		}
	}
	DFS(0,V,time);
	for(i=1; i<=n; ++i) {
		printf("%d %d %d\n",i,time[i].first,time[i].second);
	}
	return 0;
}

C++: #include <iostream>
#include <stack>
using namespace std;

const static int N = 100;
const static int WHITE = 0;
const static int GRAY = 1;
const static int BLACK = 2;

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] == 0) continue;
    if(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(u = 0; u < n; ++u){
    cout << u+1 << " " << d[u] << " " << f[u] << endl;
  }
}

int main(){
  int u, v, k;

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