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++: #ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

constexpr auto no_value = numeric_limits<uint64_t>::max();

struct GraphParser {
  GraphParser(vector<vector<int>>& edges_)
      : edges(edges_), start(edges.size(), 0), end(edges.size(), 0) {
    //
  }

  void run() {
    t = 0;
    recur(0);
  }

  vector<vector<int>>& edges;
  vector<int> start;
  vector<int> end;
  int t;

 private:
  void recur(int cur) {
    if (start[cur]) {
      return;
    }
    start[cur] = ++t;
    for (auto&& e : edges[cur]) {
      recur(e);
    }
    end[cur] = ++t;
  }
};

int main() {
  int n;
  cin >> n;
  vector<vector<int>> edges(n, vector<int>());
  for (int i = 0; i < n; ++i) {
    int u;
    int k;
    cin >> u >> k;
    edges[u - 1].reserve(k);
    for (int j = 0; j < k; ++j) {
      int v;
      cin >> v;
      edges[u - 1].push_back(v - 1);
    }
  }

  GraphParser p(edges);
  p.run();
  for (int i = 0; i < n; ++i) {
    cout << (i + 1) << " " << p.start[i] << " " << p.end[i] << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

vector<int> d;
vector<int> f;
int t;
void dfs(vector<vector<int>>Graph, int v) {
  d[v] = t;
  t++;
  if(Graph[v].size() == 0) {
    return;
  }
  for(auto next_v: Graph[v]) {
    if(d[next_v] != -1) {
      continue;
    }
    //cout << next_v << ":" << t << endl;
    dfs(Graph, next_v);
    f[next_v] = t;
    t++;
  }
  f[v] = t;
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> Graph(n);
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    rep(j, k) {
      int a;
      cin >> a;
      Graph[i].push_back(a-1);
    }
  }
  d = f = vector<int>(n, -1);
  d[0] = 1;
  t = 1;
  dfs(Graph, 0);
  f[0] = t;
  rep(i, n) {
    if(d[i] == -1) {
      t++;
      dfs(Graph, i);
      //f[i] = t;
    }
  }
  rep(i, n) {
    cout << i + 1 << " ";
    cout << d[i] << " ";
    cout << f[i] << endl;
  }
}

C++: /* 深さ優先探索
 １．一番最初に訪問する頂点をスタックに入れる
 ２．スタックに頂点が積まれている限り...
 　- スタックのトップにある頂点uを訪問する
   - 現在訪問中の頂点uから次の頂点vへ移動する時に、vをスタックへ積む。
   　uに未訪問の隣接する頂点がなければuをスタックから削除する
*/

#include <iostream>
#include <stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

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

// uに隣接するvを番号順に取得
int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (M[u][v]) return v; // 隣接する頂点vを返す
	}
	return -1; // 隣接する頂点がないなら-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; // 経過時刻を表すタイムスタンプを0に設定
	}
	tt = 0;

	// 未訪問のuを始点として深さ優先探索
	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; // 訪問中の頂点u, 次数k, 次に訪問する頂点v

	cin >> n;
	for (int i = 0; i < n; i++) { // 配列0で初期化
		for (int j = 0; j < n; j++) M[i][j] = 0;
	}

	// 無向グラフを作成
	for (int i = 0; i < n; i++) {
		cin >> u >> k; // 頂点uと出次数kを入力
		u--; // 1 -> 0オリジンに変換
		for (int j = 0; j < k; j++) {
			cin >> v; // 次に訪問する未訪問頂点v入力
			v--; // 0オリジンへ変換
			M[u][v] = 1;
		}
	}

	dfs();

	return 0;
}