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<iostream>
using namespace std;

struct vertex
{
	int id;
	int discover;
	int finish;
	bool flag;
};

static int time = 1;

void DFS(int **arr, int n, int u , vertex *ver)
{
	ver[u - 1].flag = 1;
	ver[u - 1].discover = time;
	time++;
	for (int i = 0; i < n; i++)
	{
		if (u - 1 == i)
			continue;
		if (arr[u - 1][i] == 1 && ver[i].flag == 0)
		{
			DFS(arr, n, i + 1, ver);
			time++;
		}
	}
	ver[u - 1].finish = time;
}


int main()
{
	int n = 0;
	while (cin >> n)
	{
		int **arr = new int*[n];
		vertex *ver = new vertex[n];
		for (int i = 0; i < n; i++)
		{
			arr[i] = new int[n];
			for (int j = 0; j < n; j++)
			{
				arr[i][j] = 0;
			}
			ver[i].id = i + 1;
			ver[i].flag = 0;
		}
		for (int i = 0; i < n; i++)
		{
			int u = 0;
			int k = 0;
			int v = 0;
			cin >> u >> k;
			while (k--)
			{
				cin >> v;
				arr[u - 1][v - 1]++;
			}
		}
		for (int i = 0; i < n; i++)
		{
			if(ver[i].flag == 0)
				DFS(arr, n, i + 1, ver);
		}
		for (int i = 0; i < n; i++)
		{
			cout << ver[i].id << " " << ver[i].discover << " " << ver[i].finish << endl;
		}
		time = 1;
	}

	return 0;
}

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

int visit[100],end[100],a[100][100];
int t,N,u,k,col;

void rist_to_mat(int N) {
	for(int l=0; l<N; ++l) {
		cin >> u >> k;
		for (int i=0; i<k; ++i) {
			cin >> col;
			a[u-1][col-1] = 1;
		}
	}
}

void dfs(int cur,int N) {
	t += 1;
	visit[cur] = t;
	for(int dst=0; dst<N; ++dst) {
		if(a[cur][dst] == 1 && visit[dst] == 0) {
			dfs(dst,N);
		}
	}
	t += 1;
	end[cur] = t;
}

int main() {
	cin >> N;
	rist_to_mat(N);
	for(int i=0; i<N; ++i) {
		if(visit[i] == 0) dfs(i,N);
	}
	for(int i=0; i<N; ++i) {
		cout << i+1 << ' ' << visit[i] << ' ' << end[i] << endl;
	}
}

C++: #include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

vector< vector<int> > list;
vector<int> d, f;
int t;

void dfs(int v) {
  if (d[v] != 0) {
    return;
  }
  
  d[v] = t++;
  for (int i = 0; i < list[v].size(); i++) {
    int visit = list[v][i];
    dfs(visit);
  }
  f[v] = t++;
}
  

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  t = 1;
  
  int n;
  cin >> n;

  list.resize(n+1);
  d.resize(n+1, 0);
  f.resize(n+1, 0);

  for (int i = 0; i < n; i++) {
    int u,k;
    cin >> u >> k;
    
    vector<int> row(k);
    for (int j = 0; j < k; j++) {
      cin >> row[j];
    }
    
    list[u] = row;
  }

  for (int i = 1; i <= n; i++) {
    dfs(i);
  }
  
  for (int i = 1; i <= n; i++) {
    cout << i << " " << d[i] << " " << f[i] << eol;
  }

  return 0;
}

C++: #include <stdio.h>
#include <string.h>
#define N 110
int n;
int m[N][N];
int used[N];
int time = 1;
int start[N];
int end[N];
void dfs(int u){
    used[u] = 1;
    start[u] = time++;
    for(int v = 1; v <= n; v++){
        if(used[v] == 0 && m[u][v]){
            dfs(v);
        }
    }
    end[u] = time++;
}
int main(){
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) m[i][j] = 0;
    scanf("%d", &n);
    for(int p = 0; p < n; p++){
        int node, k;
        scanf("%d %d", &node, &k);
        for(int i = 0; i < k; i++){
            int b;
            scanf("%d", &b);
            m[node][b] = 1;
        }
    }

    dfs(1);
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, start[i], end[i]);
    }
    return 0;
}

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

int G[101][102];
int found[101];
int comp[101];   // complete.
int t;  // time.

typedef struct box{ int val; box* next; } box_t;  // stack.

box_t* init()
{
    box_t* head = new box_t;
    head->val = -1;
    head->next = NULL;
    return head;
}

bool isEmpty(box_t* head){ return (head->next == NULL ? true : false); }

box_t* push(box_t* head, int data)
{
    box_t* box = new box_t;
    box->val = data;
    box->next = head->next;
    head->next = box;
    return box;
}

int pop(box_t* head)
{
    if(isEmpty(head)){ return -1; }
    box_t* box = head->next;
    int val;
    head->next = box->next;
    val = box->val;
    delete box;
    return val;
}

int front(box_t* head)
{
    int val;
    if(isEmpty(head)){ return -1; }
    val = head->next->val;
    return val;
}

box_t* stack = init();

void search_loop(int i)
{
    int j, k;
    while(1){
        if(found[i] == 0){
            t++; found[i] = t;
            push(stack, i);
        }
        for(k = G[i][0]; G[i][k] != 0 && found[G[i][k]] != 0; k++);
        if(G[i][k] == 0){
            if(isEmpty(stack)){ return; }
            else{
                j = pop(stack);
                t++; comp[j] = t;
                i = front(stack);
            }
        }else{
            G[i][0] = k + 1;
            i = G[i][k];
        }
    };
    return;
}

int main()
{
    int n, i, j, a, b, e;
    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        G[i][0] = 1;
        for(j = 1; j <= n + 1; j++){ G[i][j] = 0; } }

    for(i = 1; i <= n; i++){
        scanf("%d %d", &a, &e);
        for(j = 1; j <= e; j++){
            scanf("%d", &b); G[a][j] = b; } }  // adjacent representation.

    for(i = 1; i <= n; i++){ found[i] = 0; comp[i] = 0; }
    t = 0;
    while(1){
        for(i = 1; i <= n; i++){
            if(found[i] == 0) break;
        }
        if(i > n) break;
        search_loop(i);
    };

	printf("\n");
    for(i = 1; i <= n; i++){
        printf("%d %d %d\n", i, found[i], comp[i]);
    }
    return 0;
}