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<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
static const int N=105;
int M[N+1][N+1];
void graph(int n){
    for(int i=1;i<=n;i++){
        int garbage;cin>>garbage;
        int k;cin>>k;
        for(int j=1;j<=k;j++){
            int l;cin>>l;
            M[i][l]=1;
        }
    }
}
int d[N],f[N],t=1,n;
stack <int>S;
void dfs(){
    S.push(1);
    d[1]=t;
    while(S.empty()!=true){
        int flag=0,i=1;
        while(flag==0 && i<=n){
            if(M[S.top()][i]==0){
                i++;
            }else{
                    flag++;
                for(int z=1;z<=n;z++) M[z][i]=0;
                
            }
        }
        t++;
        if(i>=n+1){
            f[S.top()]=t;
            S.pop();
        }else{
            S.push(i);
            d[i]=t;
        }
    }
}

int main(){
    cin>>n;
    graph(n);
    dfs();
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

using ll = long long;

ll MAX_N = 1e5;
vector<vector<ll> > graph(MAX_N);
vector<bool> visited(MAX_N);

// ALDS1_11_B
vector<ll> d(MAX_N);
vector<ll> f(MAX_N);
ll t = 0;

// O(E)
void dfs(ll u){
    visited[u] = true;
    // visit v
    d[u] = ++t;
    for(ll v: graph[u]){
        if(!visited[v]){
            dfs(v);
        }
    }
    f[u] = ++t;
}

// ALDS1_11_B: verified
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    for(ll i=0;i<n;i++){
        ll u, k; cin >> u >> k;
        vector<ll> vs;
        for(ll j=0;j<k;j++){
            ll v; cin >> v;
            vs.push_back(v);
        }
        sort(vs.begin(), vs.end());
        for(ll j=0;j<k;j++){
            ll v = vs[j];
            graph[u - 1].push_back(v - 1);
        }
    }
    for(int i=0;i<n;i++){
        if(!visited[i]) dfs(i);
    }
    for(int i=0;i<n;i++) cout << i + 1 << " " << d[i] << " " << f[i] << endl;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define white 0
#define gray 1
#define black 2
const int N=100;
int n,color[N],c[N][N],tt,f[N],d[N];
void dfs_visit(int u){
    color[u]=gray;
    f[u]=++tt;
    for(int v=0;v<n;v++){
        if(c[u][v]==0)continue;
        if(color[v]==white){
            dfs_visit(v);
        }
    }
    color[u]=black;
    d[u]=++tt;
}
void dfs(){
    memset(color,0,sizeof(color));
    memset(f,0,sizeof(f));
    memset(d,0,sizeof(d));
    tt=0;
    for(int u=0;u<n;u++){
        if(color[u]==white)
        dfs_visit(u);
    }
    for(int u=0;u<n;u++)
    {
        cout<<u+1<<" "<<f[u]<<" "<<d[u]<<endl;
    }
}
int main(){
    int u,v,k;
    cin>>n;
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++){
        cin>>u>>k;u--;
        for(int j=0;j<k;j++){
            cin>>v;v--;
            c[u][v]=1;
        }
    }
    dfs();
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vqi = vector<queue<int>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void dfs(vqi &g, vi &d, vi &f, int v, int &t) {
  if (d[v] && g[v].empty()) {
    t--;
    return;
  }

  if (!d[v]) d[v] = t;

  while (!g[v].empty()) {
    int next = g[v].front(); g[v].pop();
    if (!d[next] )dfs(g, d, f, next, ++t);
  }

  f[v] = max(++t, f[v]);
}

int main() {
  int n;
  cin >> n;
  
  vqi g(n);
  rep(i, n) {
    int u, k;
    cin >> u >> k;

    rep(j, k) {
      int v;
      cin >> v;
      g[u - 1].push(v - 1);
    }
  }

  vi d(n), f(n);
  stack<int> s;
  s.push(0);

  int t = 1;
  rep(i, n) {
    dfs(g, d, f, i, t);
    t++;
  }

  rep(i, n) printf("%d %d %d\n", i + 1, d[i], f[i]);
}