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
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			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
		}
	}
	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 <algorithm>
#include <vector>
#include <utility>
using namespace std;
//_____
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef pair<int,int> pii;
//_______

vector <int> G[102];
pii d[102];
int tt;
int N;

void dfs(int u)
{
   d[u].fi = ++tt;
   rep(i, G[u].size()){
      if( d[ G[u][i] ].fi == 0 )dfs( G[u][i] );
   }
   d[u].se = ++tt;
   return ;
}

void slv()
{
   tt = 0;
   reps(i, 1, N)
      if( d[i].fi == 0 ) dfs(i);
   reps(i, 1, N)
      cout << i << ' ' << d[i].fi << ' ' << d[i].se << '\n';
}

signed main()
{
   FAST();
   int u, k, p;

   cin >> N;
   reps(i, 1, N){
      cin >> u >> k;
      while(k--){
         cin >> p;
         G[u].pb(p);
      }
   }

   slv();
   return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define F first
//#define S second

typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e12;
const ll mlnf = -1e12;
const double e = 1e-10;

using Graph = vector<vector<int>>;

void debug_vector(vector<int>& v)
{
    int n = v.size();
    for (int i = 0; i < n; i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}


//////////////////////
//// coding start ////
//////////////////////

// global variety
int N;
int d[110];
int f[110];
int ans;
// function
void solve();
void dfs(const Graph &G, int v);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

void solve(){
    cin >> N;
    Graph G(N);
    rep(i, N){
        int hoge; cin >> hoge;
        int k; cin >> k;
        rep(j, k){
            int tmp;
            cin >> tmp;
            tmp--;
            G[i].push_back(tmp);
        }
    }
    rep(i, N) d[i] = -1;
    rep(i, N) f[i] = -1;
    ans = 0;
    for (int i = 0; i < N; i++){
        if (d[i] != -1) continue;
        ans++;
        dfs(G, i);
    }
    rep(i, N){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    
    return ;    
}

void dfs(const Graph &G, int v){
    d[v] = ans;
    for(auto next_v : G[v]){
        if (d[next_v] != -1) continue;
        ans++;
        dfs(G, next_v);
    }
    ans++;
    f[v] = ans;
}

C++: #include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vector<int>>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)

vb seen;
vi k;
vi d;
vi f;

int dfs(const Graph &G, int v, int t) {
    seen[v] = true;
    d[v] = t;
    REP(i, k[v]) {
        int next_v = G[v][i];
        if (seen[next_v]) continue;
        t = dfs(G, next_v, t+1);
    }
    t += 1;
    f[v] = t;
    return t;
}

int main () {
	cin.tie(0);
   	ios::sync_with_stdio(false);

    int n; cin >> n;
    Graph G(n);
    REP(i, n) {
        int u; cin >> u;
        int tmp; cin >> tmp;
        k.push_back(tmp);
        REP(j, tmp) {
            int v; cin >> v;
            G[i].push_back(v-1);
        }
    }

    seen.assign(n, false);
    d.assign(n, 0);
    f.assign(n, 0);

    int t = 0;
    REP(i, n) {
        if (seen[i]) continue;
        t = dfs(G, i, t+1);
    }

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

C++: #include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define N 100
int M[N][N],n;
int color[N],d[N],f[N],tt;
void dfs_visit(int u)
{
  int v;
  color [u] = GRAY ;
  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++)
    {
      printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}
int main ()
{
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i = 0;i<n;i++)
   {
     for(j = 0;j<n;j++)
      M[i][j] = 0;
   }
  for(i = 0;i<n;i++)
  {
    scanf("%d %d",&u,&k);
    u--;
    for(i = 0;j<k;j++)
      {
        scanf("%d",&v);
        v--;
        M[u][v] =1;
      }
  }
  dfs();
  return  0 ;
}