Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

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

using namespace std;

const int edge = 1;
const int no_edge = 0;
const int no_time = -1;
const int no_label = -1;


// return finished time
int depth_search(
  int started_label,
  int current_time,
  vector<vector<int>> matrices_graph,
  vector<int>& discovered_times,
  vector<int>& finished_times
) {
  stack<int> visited_stack;
  int vertex_num = matrices_graph.size();
  visited_stack.push(started_label);
  discovered_times[started_label -1] = ++current_time;

  while(!visited_stack.empty()) {
    int current_label = visited_stack.top();

    // find no visited vertex
    int no_visited_label = no_label;
    for(int i = 0; i < vertex_num; i++) {
      if(matrices_graph[current_label - 1][i] != edge) {
        continue;
      }
      if(discovered_times[i] != no_time) {
        continue;
      }
      no_visited_label = i + 1;
      break;
    }

    if(no_visited_label != no_label) {
      visited_stack.push(no_visited_label);
      discovered_times[no_visited_label - 1] = ++current_time;
    } else {
      int finished_label = visited_stack.top();
      visited_stack.pop();

      finished_times[finished_label - 1] = ++current_time;
    }
  }

  return current_time;
}

int main() {
  int vertex_num;
  cin >> vertex_num;
  vector<vector<int>> matrices_graph(
    vertex_num,
    vector<int>(vertex_num, 0)
  );


  // set adjacency matrices graph
  for(int i = 0; i < vertex_num; i++) {
    int vertex_label;
    int adjacency_num;
    cin >> vertex_label >> adjacency_num;

    for(int j = 0; j < adjacency_num; j++) {
      int adjacency_label;
      cin >> adjacency_label;
      matrices_graph[vertex_label -1][adjacency_label - 1] = edge;
    }
  }

  vector<int> discovered_times(vertex_num, no_time);
  vector<int> finished_times(vertex_num, no_time);

  int current_time = 0;
  for(int i = 0; i <vertex_num; i++) {
    if(discovered_times[i] == no_time) {
      int started_label = i + 1;
      current_time = depth_search(
        started_label,
        current_time,
        matrices_graph,
        discovered_times,
        finished_times
      );
    }
  }

  for(int i = 0; i < vertex_num; i++) {
    cout << i + 1 << ' ' <<  discovered_times[i] << ' ' << finished_times[i] << endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1};
int dx[] = {1, -1, 0, 0};

int n;
int table[101][101];
int reached[101];
int back[101];
int bn = 1;
int cost = 1;
void dfs(int now) {
    //cout << bn << " " << now << " " << cost << endl;
    rrep(i, 1, n + 1) {
        if (table[now][i] == 1 && reached[i] == 0) {
            cost++;
            reached[i] = cost;
            bn = now;
            dfs(i);
        }
    }
    
    cost++;
    //cout << now << " " << cost << endl;
    back[now] = cost;
    return;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n + 1) rep(j, n + 1) table[i][j] = 0;
    rep(j, n) {
        int u, k; cin >> u >> k;
        int v;
        rep(l, k) {
            cin >> v;
            table[u][v] = 1;
        }
    }
    reached[1] = 1;
    dfs(1);
    rrep(i, 2, n + 1) {
        if (reached[i] == 0) {
            reached[i] = ++cost;
            dfs(i);
        }
    }
    rrep(i, 1, n + 1) cout << i << " " << reached[i] << " " << back[i] << endl;
    
}