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 <array>
#include <vector>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

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

int n;
int mat[100][100];
int d[100];
int f[100];

int dfs(int i, int t)
{
    d[i] = t++;

    REP(j, n) {
        if(mat[i][j] && !d[j]) {
            t = dfs(j, t);
        }
    }

    f[i] = t++;

    return t;
}

void solve()
{
    int t = 1;

    REP(i, n) {
        if(d[i]) continue;

        t = dfs(i, t);
    }
}

int main()
{
    cin >> n;

    REP(i, n) {
        REP(j, n) {
            mat[i][j] = 0;
        }
    }

    REP(_, n) {
        int u, k;
        cin >> u >> k;

        REP(_, k) {
            int v;
            cin >> v;
            mat[u-1][v-1] = 1;
        }
    }

    fill(begin(d), end(d), 0);
    fill(begin(f), end(f), 0);
    solve();

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

    return 0;
}

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

const int N = 100;
int M[N][N];
int n;
int t;
int color[N];
int d[N], f[N];

void init(){
  for(int i=0;i<n;i++){
    color[i] = 0;
  }
}

void dfs(int x){
  color[x] = 1;
  d[x] = ++t;
  for(int i=0;i<n;i++){
    if(M[x][i] == 1 && color[i] == 0){
      dfs(i);
    }
  }
  color[x] = 2;
  f[x] = ++t;
}

int main(){
  cin >> n;
  int u, k, v;
  for(int i=0;i<n;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >> v;
      M[u-1][v-1] = 1;
    }
  }
  init();
  dfs(0);
  for(int i=0;i<n;i++){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n, u;
int k[110];
int a[110][110];
int b[110];
int d[110], f[110];
int t=1;

void dfs(int v)
{
	d[v]=t;
	t++;
	b[v]++;
	for(int l=0; l<k[v]; l++)
	{
		if(b[a[v][l]]==0)
		{
			dfs(a[v][l]);
		}
	}
	f[v]=t;
	t++;
}

int main() 
{
	cin >> n;
	for(int i=0; i<n; i++)
	{
		cin >> u;
		cin >> k[u];
		for(int j=0; j<k[u]; j++)
		{
			cin >> a[u][j];
		}
	}
	for(int v=1; v<=n; v++)
	{
		if(b[v]==0)
		{
			dfs(v);
		}
		cout << v << ' ' << d[v] << ' ' << f[v] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
using ll = long long;
using namespace std;

#define WHITE 1
#define GRAY 2
#define BLACK 3

int now, n, u, k, v, tree[102][102], timeTable[102][2], color[102], timeNow = 1;
stack<int> st;

void dfs(){
    while(1){
        if(st.empty()){
          	int l = 1;
          	while(1){
              	if(l == n + 1){
                	FOR(l, 1, n + 1){
                		cout << l << " " << timeTable[l][0] << " " << timeTable[l][1] << endl;
            		}
                  	break;
                }
            	if(color[l] == WHITE){
                	st.push(l);
                  	timeNow++;
                  	break;
                }
              	l++;
            }
          	if(l == n + 1){
            	break;
            }
        }else{
            now = st.top();
          	if(color[now] == WHITE){
            	timeTable[now][0] = timeNow;
            }
            color[now] = GRAY;
            int cnt = 1;
            while(1){
                if(cnt == n + 1){
                    st.pop();
                    color[now] = BLACK;
                    timeTable[now][1] = timeNow + 1;
                    break;
                }else if(tree[now][cnt] && color[cnt] == WHITE){
                    st.push(cnt);
                    break;
                }
                cnt++;
            }
            timeNow++;
        }
    }
}

int main(){
    cin >> n;
  	REP(i, 102){
    	REP(j, 102){
        	tree[i][j] = 0;
        }
    }
    REP(i, n){
        cin >> u >> k;
        color[i + 1] = WHITE;
        REP(j, k){
            cin >> v;
            tree[u][v] = 1;
        }
    }
    st.push(1);
    dfs();
  	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,step=0,fdepth[105],sdepth[105];
bool visit[105],c[105][105];
void dfs(int node){
    step++;
    fdepth[node]=step;
    for(int i=1;i<=n;i++)
        if(!visit[i]&&c[node][i]){
            visit[i]=1;
            dfs(i);
        }
    step++;
    sdepth[node]=step;
}
int allvisit(int node){
    for(int i=1;i<=n;i++)
        if(!visit[i])
            return i;
    return 0;
}
int main(){
    ios_base::sync_with_stdio(0);
    //cin.tie(0);
    while(cin>>n){
        memset(fdepth,0,sizeof(fdepth));
        memset(sdepth,0,sizeof(sdepth));
        memset(c,0,sizeof(c));
        memset(visit,0,sizeof(visit));
        int parent,num,son;
        for(int i=0;i<n;i++){
            cin>>parent>>num;
            while(num--){
                cin>>son;
                c[parent][son]=1;
            }
        }
        step=0;
        visit[1]=1;
        dfs(1);
        while(allvisit(1)){
            step=0;
            dfs(allvisit(1));
        }
        for(int i=1;i<=n;i++)
            cout<<i<<' '<<fdepth[i]<<' '<<sdepth[i]<<'\n';
    }
    return 0;
}