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>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <climits>

#include <vector>
#include <memory>
using namespace std;

#define DEBUG (0)
#define USE_UNIQUE_PTR (0)

#if DEBUG
#define DPRINTF(...) do { \
    printf("D(L%d) %s: ", __LINE__, __func__); \
    printf(__VA_ARGS__); \
  } while (false)
#else
#define DPRINTF(...)
#endif // DEBUG

int g_time = 1;

class Vertex {
public:
  Vertex() :
    id_(-1),
    discover_time_(-1),
    finish_time_(-1),
    adjacentNum_(0),
    adjacentIds_(nullptr),
    isVisited_(false) { }

  ~Vertex() {
#if !USE_UNIQUE_PTR
    if (adjacentIds_)
      delete [] adjacentIds_;
#endif
  }

  void setAdjacency(const vector<int> &adjacentIds);

  inline void setId(int id) { id_ = id; }
  inline void setDiscoverTime(int time) { discover_time_ = time; }
  inline void setFinishTime(int time) { finish_time_ = time; }
  inline void setVisited(bool visited) { isVisited_ = visited; }

  inline int getId() { return id_; }
  inline int getDiscoverTime() { return discover_time_; }
  inline int getFinishTime() { return finish_time_; }
  inline bool getVisited() { return isVisited_; }
  inline int getAdjacentNum() { return adjacentNum_; }
  inline int getAdjacentId(int idx) {
    if (adjacentIds_ == nullptr || idx > adjacentNum_)
      return -1;
    return adjacentIds_[idx];
  }

  void printTime();
  void printAdj();

private:
  int id_;
  int discover_time_;
  int finish_time_;

  int adjacentNum_;
#if USE_UNIQUE_PTR
  unique_ptr<int[]> adjacentIds_;
#else
  int *adjacentIds_;
#endif // USE_UNIQUE_PTR

  bool isVisited_;
};


void Vertex::setAdjacency(const vector<int> &adjacentIds)
{

  adjacentNum_ = adjacentIds.size();
#if USE_UNIQUE_PTR
  adjacentIds_ = unique_ptr<int[]>(new int[adjacentNum_]);
#else
  adjacentIds_ = new int[adjacentNum_];
#endif // USE_UNIQUE_PTR

  for (int i = 0; i < adjacentNum_; i++)
  {
    adjacentIds_[i] = adjacentIds[i];
  }

}

void Vertex::printTime()
{
  printf("%d %d %d\n", id_, discover_time_, finish_time_);
}

void Vertex::printAdj()
{
  DPRINTF("%d %d", id_, adjacentNum_);
  for (int i = 0; i < adjacentNum_; i++) {
    printf(" %d", adjacentIds_[i]);
  }
  cout << endl;
}


void dfs(Vertex vertices[], int idx)
{

  DPRINTF("time %d  idx %d\n", g_time, idx);

  Vertex &vtx = vertices[idx];

  if (!vtx.getVisited())
  {
    vtx.setDiscoverTime(g_time);
    g_time++;
  }

  for (int i = 0; i < vtx.getAdjacentNum(); i++)
  {
    int id = vtx.getAdjacentId(i);
    dfs(vertices, id);
  }

  if (!vtx.getVisited())
  {
    vtx.setFinishTime(g_time);
    vtx.setVisited(true);
    g_time++;
  }

}


int main()
{
  int n;

  cin >> n; cin.ignore();
  DPRINTF("Node num %d\n", n);

  Vertex vertices[n+1];

  for (int i = 1; i <= n; i++)
  {
    int id;
    int num;

    cin >> id >> num;
    vertices[i].setId(id);
    DPRINTF("node %d (num %d)\n", id, num);

    vector<int> adjs;

    for (int j = 0; j < num; j++)
    {
      int adj;
      cin >> adj;

      adjs.push_back(adj);
    }

    if (adjs.size())
      vertices[i].setAdjacency(adjs);

    cin.ignore();
  }

#if DEBUG
  for (int i = 1; i <= n; i++) vertices[i].printAdj();
#endif

  for (int i = 1; i <= n; i++)
    if (!vertices[i].getVisited())
      dfs(vertices, i);

  for (int i = 1; i <= n; i++) vertices[i].printTime();

  return 0;
}

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

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

int M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];
int 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();

   return 0;
}

C++: #include <iostream>
#include <vector>
#include <numeric>

using namespace std;

vector<vector<int32_t>> A(101);
vector<int32_t> d(101), f(101);
int32_t t = 1;

void dfs(int32_t u) {
    d[u] = t++;

    for (int32_t v : A[u]) {
        if (d[v] == 0) {
            dfs(v);
        }
    }

    f[u] = t++;

    return;
}

int main() {
    fill(d.begin(), d.end(), 0);

    int32_t n;
    cin >> n;

    for (int32_t i = 0; i < n; i++) {
        int32_t u, k;
        cin >> u >> k;

        for (int32_t j = 0; j < k; j++) {
            int32_t v;
            cin >> v;

            A[u].push_back(v);
        }
    }

    for (int32_t i = 1; i <= n; i++) {
        if (d[i] == 0) {
            dfs(i);
        }
    }

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

    return 0;
}