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++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int m[100][100];
int n;
int used[100];
int d[100], f[100];
int ti = 0;

void dfs(int u)
{
    used[u] = 1;
    d[u] = ++ti;

    rep(i, n)
    {
        if (m[u][i] == 0)
            continue;
        if (used[i] == 0)
            dfs(i);
    }
    f[u] = ++ti;
}

int main()
{
    cin >> n;
    rep(i, n) used[i] = 0;
    rep(i, n) rep(j, n) m[i][j] = 0;

    rep(i, n)
    {
        int u, k;
        cin >> u >> k;
        --u;
        rep(j, k)
        {
            int v;
            cin >> v;
            m[u][--v] = 1;
        }
    }

    rep(i, n) if (!used[i]) dfs(i);

    rep(i, n)
    {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int N,t=0;
int d[101][101],Ts[101],Te[101];
bool visit[101];
void graph(){
    int u,k,a;
    for(int i=1;i<=N;++i){
        cin>>u>>k;
        for(int j=0;j<k;++j){
            cin>>a;
            d[u][a]=1;
        }
        visit[i]=true;
    }
}
void dfs(int cur){
    t+=1;
    Ts[cur]=t;
    visit[cur]=false;
    for(int i=1;i<=N;++i){
        if(d[cur][i]==1&&visit[i]){
            dfs(i);
        }
    }
    t+=1;
    Te[cur]=t;
}
int main(){
    cin>>N;
    graph();
    for(int i=1;i<=N;++i){
        if(visit[i]) {
            dfs(i);
        }
    }
    for(int i=1;i<=N;++i){
        cout<<i<<" "<<Ts[i]<<" "<<Te[i]<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

vector< vector<int> > list;
vector<int> d, f;
int t;

void dfs(int v) {
  if (d[v] != 0) {
    return;
  }
  
  d[v] = t++;
  for (int i = 0; i < list[v].size(); i++) {
    int visit = list[v][i];
    dfs(visit);
  }
  f[v] = t++;
}
  

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

  t = 1;
  
  int n;
  cin >> n;

  list.resize(n+1);
  d.resize(n+1, 0);
  f.resize(n+1, 0);

  for (int i = 0; i < n; i++) {
    int u,k;
    cin >> u >> k;
    
    vector<int> row(k);
    for (int j = 0; j < k; j++) {
      cin >> row[j];
    }
    
    list[u] = row;
  }

  dfs(1);

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

  return 0;
}