Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		u, k := sc.nextInt()-1, sc.nextInt()
		for j := 0; j < k; j++ {
			G[u] = append(G[u], sc.nextInt()-1)
		}
	}
	ans := make([][2]int, N)
	time := 0
	found := make(map[int]bool)
	var dfs func(cur int)
	dfs = func(cur int) {
		time++
		ans[cur][0] = time
		found[cur] = true
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !found[next] {
				dfs(G[cur][i])
			}
		}
		time++
		ans[cur][1] = time
	}
	for i := 0; i < N; i++ {
		if !found[i] {
			dfs(i)
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprint(wtr, i+1)
		for j := 0; j < 2; j++ {
			fmt.Fprint(wtr, " ")
			fmt.Fprint(wtr, ans[i][j])
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}

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

using namespace std;

class Node{
private:
 unsigned long nodeId;
 unsigned long timestampStart;
 unsigned long timestampFinish;
 vector<unsigned long> adjectNode;
 unsigned long checkedNodeNum;

 void stampStart(unsigned long time){
  timestampStart = time;
 };

 void stampFinish(unsigned long time){
  timestampFinish = time;
 };
 

public:
 Node(unsigned long nodeId = 0, unsigned long adjectNodenum = 0)
                  : nodeId(nodeId),
                    timestampStart(0),
                    timestampFinish(0),
                    adjectNode(vector<unsigned long>(adjectNodenum, 0)),
                    checkedNodeNum(0){

 for(unsigned long adjectNode_i = 0; adjectNode_i < adjectNodenum; ++adjectNode_i){
  unsigned long adjectNodeId = 0; cin >> adjectNodeId;

  adjectNode[adjectNode_i] = adjectNodeId;
 } 

 };

 unsigned long getNotCheckedAdjectNode(unsigned long time){
  unsigned long AdjectNodeMax = adjectNode.size();
  if(checkedNodeNum == 0){
   stampStart(time);
  }else if(checkedNodeNum >= AdjectNodeMax){
   stampFinish(time);
   return ULONG_MAX;
  }


  ++checkedNodeNum;

  if(AdjectNodeMax == 0){
   return nodeId-1;
  }

  return adjectNode[checkedNodeNum-1]-1;

 };

 void display(){
  cout << nodeId          << " ";
  cout << timestampStart  << " ";
  cout << timestampFinish << endl;
 };


protected:
};

class Graph{
private:
 vector<Node*> graph;

public:
 Graph(unsigned long nodeNum = 0)
                  : graph(vector<Node*>(nodeNum, 0)){
  for(unsigned long node_i = 0; node_i < nodeNum; ++node_i){
   unsigned long nodeId = 0; cin >> nodeId;
   unsigned long adjectNodenum = 0; cin >> adjectNodenum;
   Node* temp_node = new Node(nodeId, adjectNodenum);
   graph[nodeId-1] = temp_node;
  }
 };

 void DepthFirstSearch(){
  unsigned long time = 1;
  stack<unsigned long> checkedNode;
  if(graph[0] == 0) return ;

  checkedNode.push(0);
  while(!checkedNode.empty()){
   unsigned long nowNode = checkedNode.top();
   if(unsigned long nextNode = graph[nowNode]->getNotCheckedAdjectNode(time)){
    if(nextNode == ULONG_MAX){
     checkedNode.pop();
    }else if(nextNode == nowNode){
    }else{
     checkedNode.push(nextNode);
    }
   }
   ++time;
  }

 };

 void display(){
  for(unsigned long node_i = 0, nodeNum = graph.size(); node_i < nodeNum; ++node_i){
   graph[node_i]->display();
  }
 };

protected:

};

int main(){
 unsigned long nodeNum = 0; cin >> nodeNum;

 Graph graph(nodeNum);
 graph.DepthFirstSearch();
 graph.display();

 return 0;
};

C++: #include<iostream>
#include<stack>
using namespace std;
#define MAX 100
#define NIL -1

int n, T[MAX+1][MAX+1];
int laps = 0, d[MAX+1], f[MAX+1];

void solve(int i){
    d[i] = ++laps;
    for ( int j = 1; j <= n; j++){
      if ( T[i][j] && d[j] == NIL ){
        solve(j);
      }
    }

    f[i] = ++laps;
}

int main(){
  cin >> n;
  for ( int i = 1; i <= n; i++){
    d[i] = f[i] = NIL;
    for ( int j = 1; j <= n; j++){
      T[i][j] = 0;
    }
  }

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

  for ( int i = 1; i <= n; i++){
    if ( d[i] == NIL){
      solve(i);
    }
  }

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

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void dfs(int v, int &t, const V<V<int>> &g, V<P> &time) {

    t++;
    time[v].fi = t;
    for(int nv : g[v]) {
        if(time[nv].fi) continue;
        dfs(nv, t, g, time);
    }
    t++;
    time[v].se = t;
}

int main(){

    int n;
    cin >> n;
    V<V<int>> g(n);
    rep(i,n) {
        int a, k;
        cin >> a >> k;
        a--;
        rep(j,k) {
            int b;
            cin >> b;
            b--;
            g[a].push_back(b);
        }
    }
    V<P> time(n);
    int t = 0;
    rep(i,n) {
        if(time[i].fi) continue;
        dfs(i, t, g, time);
    }
    rep(i,n) {
        printf("%d %d %d\n", i+1, time[i].fi, time[i].se);
    }
}