Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) doesAllAdjsVisited(vertices []vertex) bool {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return false
		}
	}
	return true
}

func (v *vertex) isFirstVisit() bool {
	return v.firstVisitAt == 0
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func (v *vertex) nextVertex(vertices []vertex) (vertexId, error) {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return vId, nil
		}
	}
	return vertexId(-1), fmt.Errorf("illegal")
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	timestamp = timestamp + 1
	currentVertex := &vertices[currentId-1]
	if currentVertex.isFirstVisit() {
		currentVertex.firstVisitAt = timestamp
	}
	for !currentVertex.doesAllAdjsVisited(vertices) {
		nextVertexId, _ := currentVertex.nextVertex(vertices)
		timestamp = dfs(nextVertexId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	dfs(vertexId(1), 0, vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

C++: #include <cstdio>

typedef struct vertex_{
    int found;
    int d;
    int f;
}vertex;

int search(vertex *array, int (*A)[101], int id, int n, int time){
    if(array[id].found)return time;
    array[id].found=1;
    time++;
    array[id].d=time;
    for(int i=1;i<=n;i++){
        if(A[id][i])time=search(array,A,i,n,time);
    }
    time++;
    array[id].f=time;
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    vertex array[n+1];
    for(i=1;i<=n;i++)array[i].found=0;
    int A[101][101];
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            A[i][j]=0;
        }
    }
    for(i=1;i<=n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            A[u][v]=1;
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            printf("%d ",A[i][j]);
        }
        printf("\n");
    }
    int time = 0;
    for(i=1;i<=n;i++)if(array[i].found==0)time += search(array, A, i, n, 0);
    for(i=1;i<=n;i++)printf("%d %d %d\n",i,array[i].d,array[i].f);
    printf("%d\n",time);
    return 0;
}

C++: #include <algorithm>
#include <iostream>
using namespace std;
int n, Time, A[100][100], d[100], f[100];
void dfs (int cur) { //cur????¨????
  d[cur] = Time; //cur????¨??????????????¨????
  Time++;
  for (int i=0; i<n; i++) { //??¨????????????????????????
    if (A[cur-1][i]==1 && d[i+1]==0) //cur??????i??????????????????i???????¨??????????
      dfs (i); //i?????¨??¶
  }
  f[cur] = Time; //cur???????????????????¨????
  Time++;
}

int main () {
  cin >> n; //???????????????
  for (int i=0; i<n; i++) { //?????????
    for (int j=0; j<n; j++)
      A[i][j] = 0;
  }
  while (n>0) {
    int u;
    cin >> u;
    int k;
    while (cin>>k && k>0) {
      int v;
      cin >> v;
      A[u-1][v-1] = 1; //??\???
      k--;
    }
    n--;
  }
  Time = 1;
  for (int i=0; i<n; i++) {
    d[i] = 0;
  }
  for (int i=0; i<n; i++) {
    if (d[i]==0)
      dfs (i); //??¢?´¢
  }
  for (int i=1; i<=n; i++) //??????
    cout << i << " " <<  d[i] << " " << f[i] << endl;
}

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

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

C++: #include <bits/stdc++.h>
int n,G[101][101];
int d[101];
int T = 0;
int F[101] = {0};
int k = 0;
 
void visit(int u) {
  int i,j,v;
  T++;  
  d[u] = T;
 
  for(v=0;v<n;v++) {
    if(G[u][v] == 1 && d[v] == 0 ) {
      visit(v);
    }
  }
   
  T++;
  F[u] = T;
 
}
 
 
 
int main() {
   
   
  int i,j,k,l,u,a,t;
 
  for(i=0;i<n;i++) d[i] = 0;
 
  scanf("%d",&n);
 
  for(i=0;i<n+1;i++)
    for(j=0;j<n+1;j++) {
      G[i][j] = 0;
 
    }
 
  for(i=0;i<n;i++){
 
    scanf("%d %d ",&k,&u);
    //    printf("u = %d\n",u);
 
    for(j=0;j<u;j++) {
      scanf("%d",&a);
      G[k -1][a-1] = 1;
      // printf("G[%d][%d] = 1\n",i,k-1);
    }
  }
  for(i=0;i<n;i++) {
    if(d[i] == 0) 
    visit (i);
  }
     
  for(i=0;i<n;i++) {
    printf("%d %d %d\n",i+1,d[i],F[i]);
  }
  return 0;
 
     
     
}