Go: package main

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

const MAX = 101

var f [MAX]int
var d [MAX]int
var list [][]int
var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func dfs(u, cnt int) int {
	if d[u] != 0 {
		return cnt
	}

	cnt++
	d[u] = cnt
	for _, next := range list[u] {
		cnt = dfs(next, cnt)
	}
	cnt++
	f[u] = cnt
	return cnt
}

func main() {
	n := scanInt()
	list = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			n := scanInt()
			list[u] = append(list[u], n)
		}
	}

	cnt := 0
	for i := 1; i <= n; i++ {
		cnt = dfs(i, cnt)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, d[i])
		fmt.Fprint(w, " ")
		fmt.Fprint(w, f[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

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

C++: #include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

int g[101][101],n,d[101],f[101];

int main() {
    cin >> n;
    for(int i = 0;i < n;i++) {
        int u,k,v;
        cin >> u >> k;
        for(int j = 0;j < k;j++) {
            cin >> v;
            g[u][v]++;
        }
    }
    stack<int> dfs;
    int time = 2;
    dfs.push(1);
    d[1] = 1;
    while(!dfs.empty()){
        int u = dfs.top();
        bool fl = false;
        for(int i = 1;i <= n;i++){
            if(g[u][i] && d[i] == 0 && u != i) {
                dfs.push(i);
                d[i] = time++;
                fl = true;
                break;
            }
        }
        if(!fl) {
            dfs.pop();
            f[u] = time++;
        }
    }
    for(int i = 1;i <=n;i++) {
        cout << i << " " << d[i] << " " << f[i] <<endl;
    }
}