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<cstdio>
#define WHITE 0
#define GRAY  1
#define BLACK 2
#define MAX 100

void InitializeBoolMatrix(int nmbr_of_rows, int nmbr_of_columns, bool mtrx[][MAX]){
	for (int row = 0; row < nmbr_of_rows; ++row) {
		for (int column = 0; column < nmbr_of_columns; ++column)
			mtrx[row][column] = false;
	}
}

void ListToMatrix(int number_of_vertices, bool mtrx[][MAX]){
	int vertex_from, vertex_to, degree_out;	
	for (int vertex_i = 0; vertex_i < number_of_vertices; ++vertex_i) {
		scanf("%d %d", &vertex_from, &degree_out);
		vertex_from--; //0?????????????????????
		for (int vertex_out_i = 0; vertex_out_i < degree_out; ++vertex_out_i) {
			scanf("%d", &vertex_to);
			vertex_to--; //0?????????????????????
			mtrx[vertex_from][vertex_to] = true;
		}
	}
}

void BuildAdjacencyMatrix(int n, bool adjmtrx[][MAX]){
	InitializeBoolMatrix(n, n, adjmtrx);
	ListToMatrix(n, adjmtrx);
}

bool adjmtrx[MAX][MAX];
int color[MAX];
int time;
int discoveredtime[MAX];
int finishedtime[MAX];

void Dfs(int present_vertex, int n){
	int pv = present_vertex;
	color[pv] = GRAY;
	discoveredtime[pv] = ++time;
	for(int v = 0;v < n;v++){
		if(adjmtrx[pv][v] && color[v] == WHITE){
			Dfs(v, n);
		}
	}
	color[pv] = BLACK;
	finishedtime[pv] = ++time;
}

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

int main(){
	int number_of_vertices;
	scanf("%d", &number_of_vertices);
	int n = number_of_vertices;
	BuildAdjacencyMatrix(n, adjmtrx);
	DfsInit(n);
	for (int vertex_i = 0; vertex_i < n; ++vertex_i){
		if(color[vertex_i] == WHITE)
		Dfs(vertex_i, n);
	}
	for (int id = 0; id < n; ++id)
		printf("%d %d %d\n", id+1, discoveredtime[id], finishedtime[id]);
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > v(101);
int dp[101][2] = { 0 };
int n, t = 0;
 
void dfs(int a) {
    if (dp[a][0] == 0) { t++; dp[a][0] = t; }
    else { return; }
    for (int i = 0;i < v[a].size();i++) {
        if (dp[v[a][i]][0] == 0) {
            dfs(v[a][i]);
        }
    }
    if (dp[a][1] == 0) { t++; dp[a][1] = t; }
}
 
int main() {
    cin >> n;
    for (int i = 0; i < n;i++) {
        int u,k; cin >> u >> k;
        for (int j = 0; j < k;j++) {
            int x; cin >> x;
            v[u].push_back(x);
        }
    }
    for (int i = 1; i <= n;i++) {
        dfs(i);
    }
    for (int i = 1; i <= n;i++) {
        cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << endl;
    }
}

C++: #include <iostream>
using namespace std;
int d[105]={0},f[105]={0};
bool vi[105]={0};
int Time=0;
int k[105][105];

void dfs(int r,int n){

	vi[r]=true;
	d[r]=Time;
for(int i=0;i<n;i++){
	if(vi[i]!=true && k[r][i]==1){
		Time=Time+1;
		d[i]=Time;
		dfs(i,n);
		f[i]=Time;
	}
}
Time=Time+1;
f[r]=Time;
}
int main() {
int n,l,a,b;
cin>>n;
for(int j=0;j<n;j++){
	cin>>l>>a;
	for(int i=0;i<a;i++){
		cin>>b;
		k[j][b-1]=1;
	}
}
for(int g=0;g<n;g++){
	if(vi[g]!=true){
		Time=Time+1;
		dfs(g,n);
	}
	
}
for(int k=0;k<n;k++){

cout<<k+1<<" "<<d[k]<<" "<<f[k]<<endl;
}	
	return 0;
}

C++: 6
1 2 2 4
2 1 5
3 2 5 6
4 0
5 1 4
6 1 6

C++: #include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>

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

int n, adj_mat[N][N];
int color[N], d[N], f[N], tt;

int Next(int node_id)
{
    for (int i = 0; i < n; i++) {
        if (adj_mat[node_id][i] == 1 && color[i] == WHITE) {
            return i;
        }
    }
    return -1;
}

void DFS(int node_id)
{
    std::stack<int> S;
    S.push(node_id);
    color[node_id] = GRAY;
    d[node_id] = tt++;

    while(!S.empty()) {
        int target = S.top();
        int next = Next(target);
        if (next != -1) {
            color[next] = GRAY;
            d[next] = tt++;
            S.push(next);
        } else {
            S.pop();
            color[target] = BLACK;
            f[target] = tt++;
        }
    }
}

void Init(int n)
{
    tt = 1;
    for (int i = 0; i < n; i++) {
        d[i] = 0;
        f[i] = 0;
        color[i] = WHITE;
        for (int j = 0; j < n; j++) {
            adj_mat[i][j] = 0;
        }
    }
}

int main(int argc, char *argv[])
{
    scanf("%d", &n);

    Init(n);    

    // make adj matrix
    for (int i = 0; i < n; i++) {
        int node_id, adj_num;;
        scanf("%d", &node_id);
        scanf("%d", &adj_num);
        node_id--;
        for (int j = 0; j < adj_num; j++) {
            int adj_id;
            scanf("%d", &adj_id);
            adj_id--;
            adj_mat[node_id][adj_id] = 1;
        }
    }

    // depth search
    for (int i = 0; i < n; i++) {
        if (color[i] == WHITE) DFS(i);
    }

    // dump adj matrix
    for (int i = 0; i < n; i++) {
        fprintf(stdout, "%d %d %d\n", i+1, d[i], f[i]);
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
typedef long long ll;
#define int ll

int g[105][105], d[105], f[105];
int presenttime = 1, n;
bool is_search[105];

void dfs(int p) {
  d[p] = presenttime++;
  is_search[p] = true; // ??????????????§?????§??????

  for (int i = 0; i < n; i++) {
    if(is_search[i] == false && g[p][i] && p != i) dfs(i);
  }
  if (f[p] == 0) f[p] = presenttime++;
}

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

  fill(is_search, is_search + n, false);

  cin >> n;

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

  int s = 0, i;

   while(1) {
    dfs(s);

    for (i = 0; i < n; i++) {
      if (is_search[i] == false) {
        s = i;
        break;
      }
    }
    if(i == n) break;
   }

   for (i = 0; i < n; i++) {
     cout << i+1 << " " << d[i] << " " << f[i] << endl;
   }
   return 0;
}