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

	timer := 1
	for {
		startNode := findStartNode(childrenMap, timeRecordMap)
		if startNode > 0 {
			visit(startNode, &timer, childrenMap, timeRecordMap)
		} else {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	if x < 0 {
		return -1
	}

	found := false
	i := 0
	for i < len(childrenMap) {
		children := childrenMap[i]
		for j := 0; j < len(children); j++ {
			if children[j] == x {
				x = j + 1
				found = true
				break
			}
		}
		if found {
			i = 0
		} else {
			i++
		}
	}
	return x
}

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 <iostream>
#include <string>
#include <algorithm>
using namespace std;

int g[101][101], d[101], f[101];

int dfs(int id, int t)
{
    if(d[id]) return t;
    d[id]=++t;
    int n=g[id][0];
    for(int i=1; i<=n; i++) {
        t=dfs(g[id][i], t);
    }
    f[id]=++t;
    return t;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        int id, k;
        cin>>id>>k;
        g[id][0]=k;
        for(int j=1; j<=k; j++) {
            cin>>g[id][j];
        }
    }
    int t=0;
    for(int i=1; i<=n; i++) t=dfs(i, t);
    for(int i=1; i<=n; i++) cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = 1LL<<60;

ll N;
int White = -1, Gray = 0, Black = 1;

vector<vector<ll> > M(110,vector<ll>(110));
vector<ll> color(110,White);
ll d[110],f[110];
vector<ll> nt(110,0);

ll tt = 0;

int next(int u){
    for(int v = nt[u]; v < N; v++){
        nt[u] = v + 1;
        if(M[u][v]) return v;
    }
    return -1;
}

void dfs(ll u){
    
    stack<int> S;
    S.push(u);
    color[u] = Gray;
    d[u] = ++tt;

    while(!S.empty()){
        u = S.top();
        ll v = next(u);
        if(v != -1){
            if(color[v] == White){
                color[v] = Gray;
                d[v] = ++tt;
                S.push(v);
            }
        }else {
            S.pop();
            color[u] = Black;
            f[u] = ++tt;        }
    }
}

int main(){
    cin >> N;
    rep(i,N){
        ll u,k; cin >> u >> k;
        u--;
        rep(j,k){
            ll v; cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    rep(i,N){
        if(color[i] == White) dfs(i);
    }

    rep(i,N){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
VI edges[100];
int d[100];
int f[100];
int tern = 0;
void dfs(int c) {

  if(d[c] != 0)
    return;

  d[c] = tern;

  rep(i, edges[c].size()) {
    if(d[edges[c][i]] == 0) {
      tern++;
      dfs(edges[c][i]);
    }
  }
  tern++;
  // cout << c << ":" << tern << endl;
  f[c] = tern;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  rep(i, n) {
    int _, k, x;
    cin >> _ >> k;
    rep(j, k) {
      cin >> x;
      x--;
      edges[i].push_back(x);
    }
  }
  rep(i, n) {
    if(d[i] == 0) {
      tern++;
      dfs(i);
    }
  }

  rep(i, n) { cout << i + 1 << " " << d[i] << " " << f[i] << endl; }

  return 0;
}

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

using namespace std;

typedef struct{
  int begin;
  int end;
  bool f;
}fint;
fint T[101];
int times = 1;
int n;
int graph[101][101];

void bfs(int now){

  int cnt = 0;
  for( int i = 1 ; i <= n ; i++ ){
    if( graph[now][i] && !T[i].f ){
      if( T[now].begin == 0 ){
	T[now].begin = times++;
      }
      T[i].f = true;
      bfs(i);
    }else cnt++;
  }
  if( cnt == n ) T[now].begin = times++;
  T[now].end = times++;
}

int main(void){

  int s,t,u;
  cin >> n;
  for( int i = 0 ; i < n ; i++ ){
    cin >> s >> t;
    for( int j = 1 ; j <= t ; j++ ){
      cin >> u;
      graph[s][u] = 1;
    }
  }
  for( int i = 1 ; i <= n ; i++ ){
    T[i].begin = 0;
    T[i].end = 0;
    T[i].f = false;
  }
  bfs(1);

  for( int i = 1 ; i <= n ; i++ ){
    cout << i << " " << T[i].begin << " " << T[i].end << endl;
  }


  return 0;
}