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<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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

void dfs_visit(int u) {
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for ( v = 0; v < n; v++ ) {
    if ( M[u][v] == 0) continue;
    if ( color[v] == WHITE )
      dfs_visit(v);
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

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

  for ( u = 0; u < n; u++ )
    if ( color[u] == WHITE ) dfs_visit(u);
  for ( u = 0; u < n; u++ )
    printf("%d %d %d\n", u + 1, d[u], f[u]);
}

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

  scanf("%d", &n);
  for ( i = 0; i < n; i++ )
    for ( j = 0; j < n; j++ ) M[i][j] = 0;

  for ( i = 0; i < n; i++ ) {
    scanf("%d %d", &u, &k);
    u--;
    for ( j = 0; j < k; j++ ) {
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

C++: #include<cstdio>
#include<array>
#include<vector>
#include<stack>
using namespace std;
const int MAX_V=101;
array<int,MAX_V> open{0};
array<int,MAX_V> close{0};
array<vector<int>,MAX_V> edge;
int t=0;

void dfs(int f){
  open[f]=++t;
  for(int a:edge[f]){
    if(open[a]==0){
      dfs(a);
    }
  }
  close[f]=++t;
}

int main(){
  int n;scanf("%d",&n);
  for(int i=0;i<n;i++){
    int u;scanf("%d",&u);
    int k;scanf("%d",&k);
    for(int j=0;j<k;j++){
      int v;scanf("%d",&v);
      edge[u].push_back(v);
    }
  }
  dfs(1);
  for(int i=0;i<n;i++){
    printf("%d %d %d\n",i+1,open[i+1],close[i+1]);
  }
}

C++: #include <iostream>

constexpr int MAXN = 100;
int V[MAXN][MAXN];
int D[MAXN];
int F[MAXN];

template<int STACK_SIZE, typename T = int>
class Stack {

public:
    Stack() {};

    void Push(T val) {
        if (top_ < STACK_SIZE) {
            stack_[top_++] = val;
        }else{
            std::cerr << "Stack over flow..." << std::endl;
            exit(-11);
        }
    };
    bool Pop() {
        if (top_ > 0) {
            stack_[--top_];
            return true;
        }
        return false;
    };

    T Top() {
        return stack_[top_ - 1];
    }

    int Size() {return top_;}


private:
    int max_size_ = STACK_SIZE;
    int top_ = 0;
    T stack_[STACK_SIZE];
};

Stack<MAXN, int> S;

int main() {

    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        int id, e_num;
        std::cin >> id >> e_num;
        for (int j = 0; j < e_num; j++) {
            int t;
            std::cin >> t;
            V[id - 1][t - 1] = 1;
        }
    }
    S.Push(0);

    int cnt = 1;
    D[0] = cnt;
    while (S.Size()) {
        for (int i = 0; i < n; i++) {
            if ((V[S.Top()][i] == 1) && (D[i] == 0)) {
                S.Push(i);
                D[i] = ++cnt;
                break;
            }
            if (i == n - 1) {
                F[S.Top()] = ++cnt;
                S.Pop();
            }
        }
    }

    for (int i = 0; i < n; i++) {
        std::cout << i + 1 << " " << D[i] << " " << F[i] << std::endl;
    }

}

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

int graph[MAX_N+1][MAX_N+1];
int d[MAX_N+1];
int f[MAX_N+1];

int n;
void dfs(int id) {
  static int t = 0;
  t++;
  d[id] = t;
  for(int i=1;i<=n;i++) {
    if(graph[id][i] != 0 && d[i] == 0) {
      dfs(i);
    }
  }
  t++;
  f[id] = t;
}

int main() {
  cin >> n;
  int u,k,v;
  for(int i=0;i<n;i++) {
    cin >> u >> k;
    for(int j=0;j<k;j++) {
      cin >> v;
      if(graph[u][v] == 0)
        graph[u][v] = 1;
    }
  }

  dfs(1);

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