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<iostream>
#include<stack>

using namespace std;

static const int N = 100;
static const int UNVISITED = 0;
static const int VISITING = 1;
static const int VISITED = 2;


int n;
int A[N][N];
int d[N];
int f[N];
int states[N];
int nt[N];
int t;

int next(int u){
  for(int v = nt[u];v < n;v++){
    nt[u] = v + 1;
    //cout << nt[u] << '\n';
    if(A[u][v]) return v;
  }
  return -1;
}

void dfs_visit(int x){
  for(int i = 0;i < n;i++){
    nt[i] = 0;
  }
  
  stack<int> s;
  s.push(x);
  states[x] = VISITING;
  d[x] = ++t;
  
  while(!s.empty()){
    int u = s.top();
    int v = next(u);
    //cout << "u:" << u << " v:" << v << '\n';
    if(v != -1){
      if(states[v] == UNVISITED){
	states[v] = VISITING;
	d[v] = ++t;
	s.push(v);
      }
    }else{
      s.pop();
      states[u] = VISITED;
      f[u] = ++t;
    }
  }
}

void dfs(){
  for(int i = 0;i < n;i++){
    states[i] = UNVISITED;
  }

  t = 0;

  for(int u = 0;u < n;u++){
    if(states[u] == UNVISITED) dfs_visit(u);
  }
  for(int i = 0;i < n;i++){
    cout << i + 1 << " " << d[i] << " " << f[i] << '\n';
  }
}
         
int main(){ 
  cin >> n;
  
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      A[i][j] = 0;
    }
  }
  
  int k,u,v;
  
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    u--;
    for(int j = 0;j < k;j++){
      cin >> v;
      v--;
      A[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

C++: #include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<LL, LL>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<LL>;

//==============================================
int n, tm = 0;
vvi M;
vi D, F, searchStatus;

void dfs(int u) {
	searchStatus[u] = 0;
	D[u] = ++tm;
	REP3(i, 1, n) {
		if (M[u][i] == 0) continue;

		if (searchStatus[i] == -1) {
			dfs(i);
		}
	}
	F[u] = ++tm;
	searchStatus[u] = 1;
}

void print() {
	REP3(i, 1, n) {
		cout << i << " " << D[i] << " " << F[i] << "\n";
	}
}

void solve() {
	REP3(i, 1, n) searchStatus[i] = -1;

	REP3(i, 1, n) {
		if (searchStatus[i] == -1) {
			dfs(i);
		}
	}

	print();
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	
	M.resize(n + 1, vi(n + 1));
	D.resize(n + 1);
	F.resize(n + 1);
	searchStatus.resize(n + 1);

	int u, k, v;
	REP3(i, 1, n) {
		cin >> u >> k;
		REP3(j, 1, k) {
			cin >> v;
			M[u][v] = 1;
		}
	}

	solve();
	return 0;
}