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

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

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 <bits/stdc++.h>
using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

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_visit(int r){
    for(int i=0;i<N;i++) nt[i] = 0;

    stack<int> s;
    s.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!s.empty()){
        int u = s.top();
        int 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;
        }
    }
}

void dfs(){
    for(int i=0;i<n;i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    for(int u=0;u<n;u++){
        if(color[u] == WHITE)
            dfs_visit(u);
    }
    for(int i=0;i<n;i++){
        cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

int main(){
    int u,k,v;

    cin >> n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            M[i][j] = 0;

    for(int i=0;i<n;i++){
        cin >> u >> k;
        u--;

        for(int j=0;j<k;j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int n = 0;
int u = 0;
int k[100];
int v[100][100];
int Discover[100] = { 0 };
int End[100] = { 0 };
//int nx = 0;
int p = 0;
void dfs(int l) {
	int i;
	int j;
	if (!Discover[l]) {
		Discover[l] = ++p;

		for (i = 0; i < n + 1; i++) {
			if (v[l][i]) {
				dfs(v[l][i]);
			}
		}
		End[l] = ++p;
	}
}
int main()
{
	int i;
	int j;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u ;
		cin >> k[u];
		for (j = 0; j < k[u]; j++) {
			cin >> v[u][j];
		}
	}
	for (i = 1; i < n + 1; i++) {
		if (!Discover[i]) {
			dfs(i);
		}
	}
	for (i = 1; i < n + 1; i++) {
		cout << i << " " << Discover[i] << " " << End[i] << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std; 
struct TIMECOUNT {
	int d, f;
};
int main()
{
	int n, u, k, vv, time = 0;
	cin >> n;
	vector<TIMECOUNT> timecount(n);
	for (int variable = 0; variable < n; ++variable) {
		timecount[variable].d = 0;
		timecount[variable].f = 0;
	}
	vector<int> a;
	vector< vector<int> > v(n);
	for (int variable1 = 0; variable1 < n; ++variable1) {
		cin >> u >> k;
		for (int variable2=0; variable2 < k; ++variable2) {
			cin >> vv;
			v[variable1].push_back(vv);	
		}
		sort(v[variable1].begin(), v[variable1].end());
	}
	a.push_back(1);
	while (timecount[0].f == 0) {
		while (v[a.back() - 1].size() != 0) {
			++time;
			timecount[a.back() - 1].d = time;
			for (int variable = 0; variable < v[a.back() - 1].size(); ++variable) {
				if (timecount[v[a.back() - 1][variable] - 1].d == 0)
					a.push_back(v[a.back() - 1][variable]);
				else
					break;
			}
		}
		while (v[a.back() - 1].size() == 0) {
			++time;
			timecount[a.back() - 1].f = time;
			a.pop_back();
		}
	}
	for (int i = 0; i < n; ++i) {
		cout << i + 1 << " " << timecount[i].d << " " << timecount[i].f << endl;
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits.h>
using namespace std;
bool flag[101];
int d[101];
int f[101];
vector<int> v[101];
int t;
void dfs(int node){
	flag[node] = true;
	d[node] = t;
	bool finished = true;
	if (finished && f[node] == 0) f[node] = t;
	for (int i = 0; i < v[node].size(); ++i){
		int tmp = v[node][i];
		if (!flag[tmp]){
			++t;
			dfs(tmp);
			++t;
		}
	}
	f[node] = t;
}
int main(){
	int n; scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		int u, k; scanf("%d %d",&u,&k);
		int tmp;
		for (int j = 0; j < k; ++j){
			scanf("%d", &tmp);
			v[u].push_back(tmp);
		}
	}
	v[0].push_back(1);
	dfs(0);
	++t;
	for (int i = 1; i <= n; ++i){
		if (d[i] == 0) dfs(i);
	}
	
	for (int i = 1; i <= n; ++i){
		cout << i << ' ' << d[i] << ' ' << f[i]+1 << '\n';
	}
}

C++: #include <stdio.h>
 #define GRAY 1
#define WHITE 0
#define BLACK 2
 
int de[101], f[101], col[101];
int A[101][101];
int n, time;
 
void visit(int u) {
  int v;
   col[u] = GRAY;
   de[u] = ++time;
 
  for (v = 1; v <= n; v++) {
    if (col[v] == WHITE && A[u][v] == 1) visit(v);
  }
  col[u] = BLACK;
  f[u] = ++time;
}
 
void dfs() {
  int u;
  for (u = 1; u <= n; u++) {
    col[u] = WHITE;
  }
  time = 0;
  for (u = 1; u <= n; u++) {
    if (col[u] == WHITE) {
      visit(u);
    }
  }
}
 
int main() {
  int i, j, u, k, v;
 
  scanf("%d\n", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &u, &k);
    for (j = 1; j <= k; j++) {
      scanf("%d ", &v);
      A[u][v] = 1;
    }
  }
 
  dfs();
  for (i = 1; i <= n; i++) {
    printf("%d %d %d\n", i, de[i], f[i]);
  }
 
 
  return 0;
}

C++: #include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

vector<bool> seen;
vector<int> first_order;
vector<int> last_order;

void dfs(const vector<vector<int>> &G, int v, int& count)
{
first_order[v]=count+1;
count++;
seen[v]=true;
for(auto next_v : G[v])
{
if(seen[next_v])continue;
dfs(G, next_v, count);
}
last_order[v]=count+1;
count++;
}

int main()
{
int n,u,k;scanf("%d", &n);
vector<vector<int>> G(n);
for(int i=0;i<n;i++)
{
scanf("%d %d", &u, &k);
for(int i=0;i<k;i++){int v;scanf("%d", &v);G[u-1].push_back(v-1);}
}
seen.assign(n,false);
first_order.resize(n);
last_order.resize(n);
int count=0;
for(int i=0;i<n;i++){if(seen[i])continue;dfs(G, i, count);}
for(int i=0;i<n;i++){printf("%d %d %d\n", i+1, first_order[i], last_order[i]);}
}