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

using namespace std;

void dfs(int);
#define N 100
int t = 0;
int s[N], f[N], color[N];
int a[N][N];

int main(int argc, char const *argv[]) {
  int n;  cin >> n;
  for (int i = 0; i < n; ++i) {
    int u, k;  cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      int v;  cin >> v;
      a[u - 1][v - 1] = 1;
    }
  }
  for (int i = 0; i < n; ++i) {
    color[i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    if (color[i] == 1) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << i + 1 << " " << s[i] << " " << f[i] << '\n';
  }

  return 0;
}

void dfs(int x) {
  color[x] = 2;
  s[x] = ++t;
  for (int i = 0; i < N; ++i) {
    if (a[x][i] == 0) {
      continue;
    }
    if (color[i] == 1) {
      dfs(i);
    }
  }
  color[x] = 3;
  f[x] = ++t;
}

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

const int MAX_N = 100;
vector<int> G[MAX_N];
int d[MAX_N], f[MAX_N];
bool used[MAX_N];

int stamp;

void dfs(const int v) {
    d[v] = stamp++;
    used[v] = true;
    for(int i = 0; i < (int)G[v].size(); i++) {
        int u = G[v][i];
        if(used[u] == false) dfs(u);
    }
    f[v] = stamp++;
}

int main() {
    int N; cin >> N;
    for(int i = 0; i < N; i++) {
        int u, k; cin >> u >> k; u--;
        while(k--) {
            int v; cin >> v; v--;
            G[u].push_back(v);
        }
        sort(G[u].begin(), G[u].end());
    }

    fill(used, used + N, false);
    stamp = 1;
    for(int i = 0; i < N; i++) {
        if(used[i] == false) dfs(i);
    }

    for(int i = 0; i < N; i++) {
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

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

int n,d[N][N],m[N],f[N],s[N],ti;
void dfs(int t){
  if(s[t]==1) return;
  ti++,m[t]+=ti,s[t]=1;
  for(int i=1;i<=n;i++) if(d[t][i]==1 && s[i]==0)dfs(i);
  ti++,f[t]+=ti;
}

int main(){
  int nx,s,fst;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>fst>>nx;
    for(int j=0;j<nx;j++){
      cin>>s;
      d[fst][s]=1;
    }
  }
  for(int i=1;i<=n;i++) dfs(i);
  for(int i=1;i<=n;i++) cout<<i<<" "<<m[i]<<" "<<f[i]<<endl;
  
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>
#include <iomanip>
#include <map>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

void printFixedDouble(double d, int fix) {
    cout << std::fixed;
    cout << std::setprecision(fix) << d << endl;
}

int timestamp = 1;

void search(int index, vector<vector<int> > &graph, vector<int> &dest, vector<int> &fin) {
    if (dest[index - 1] != -1) return;
    dest[index - 1] = timestamp;
    timestamp++;
    for (int& dsts: graph[index - 1]) {
        search(dsts, graph, dest, fin);
    }
    fin[index - 1] = timestamp;
    timestamp++;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int> > graph(n, vector<int>());

    rep(i, n) {
        int index, k;
        cin >> index >> k;
        rep(j, k) {
            int dst;
            cin >> dst;
            graph[index - 1].push_back(dst);
        }
    }

    
    vector<int> dest(n, -1);
    vector<int> fin(n, -1);

    rep(i, n) {
        search(i + 1, graph, dest, fin);
    }

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

C++: #include <iostream>
#include "memory.h"
#include <stack>

using namespace std;

bool matrix[100][100];
int n;

int next(int k){
	for(int i = 0; i < n; i++){
		if(matrix[k][i] == true)
			return i + 1;
	}
	return false;
}

int main(){
	int index, temp, num, current, count = 1;
	int start_end[100][2];
	stack<int> back;

	memset(matrix, 0, sizeof(matrix));
	memset(start_end, 0, sizeof(start_end));

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> index >> num;
		while(num--){
			cin >> temp;
			matrix[index-1][temp-1] = true;
		}
	}
	back.push(0);
	current = 0;
	while(!back.empty()){
		int r;
		r = next(current);
		if(start_end[current][0] == 0){
			start_end[current][0] = count;
			count++;
		}
		if(r){
			matrix[current][r-1] = false;
			back.push(current);
			current = r - 1;
		}
		else{
			if(start_end[current][1] == 0){
				start_end[current][1] = count;
				count++;
			}
			current = back.top();
			back.pop();
		}
		
	}
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << start_end[i][0] << " " << start_end[i][1] << endl;
	}


}

C++: #include<iostream>
#include<stack>
using namespace std;
#define White 0
#define Black 1
#define Red 2
#define MAX 100
struct Queue {
	int color, d, f, relate[MAX], roots, id;
};
Queue Q[MAX];
stack<int> q;
stack<int> dmax;
int search(int deep) {
	while (!q.empty()) {
		int s = q.top();
		int whitecount = 0;
		for (int i = 0; i < Q[s - 1].roots; i++) {
			int nakami = Q[s - 1].relate[i];
			if (Q[nakami - 1].color == White) {
				whitecount += 1;
				deep += 1;
				Q[nakami - 1].color = Black;
				q.push(Q[nakami - 1].id);
				Q[nakami - 1].d = deep;
				search(deep);
			}
		}
		if (whitecount == 0) {
			deep += 1;
			Q[s - 1].f = deep;
			dmax.push(deep);
			Q[s - 1].color = Red;
			q.pop();
			search(deep);
		}
	}
	return dmax.top();
}
int main() {
	int n, u, k, v;
	cin >> n;
	for (int i = 0; i < n; i++) {
		Q[i].color = White;
	}
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		Q[u - 1].id = u;
		Q[u - 1].roots = k;
		if (i == 0) {
			Q[u - 1].d = 1;
			Q[u - 1].color = Black;
			q.push(u);
		}
		if (k != 0) {
			for (int i = 0; i < k; i++) {
				cin >> v;
				Q[u - 1].relate[i] = v;
			}
		}
	}
	int max = search(1);
	for (int i = 0; i < n; i++) {
		if (Q[i].color == White) {
			Q[i].d = max + 1;
			q.push(Q[i].id);
			search(max+1);
			max = search(max);
		}
	}
	for (int i = 0; i < n; i++) {
		cout << Q[i].id << " " << Q[i].d << " " << Q[i].f << endl;
	}

}