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) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

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)
	}

	solveDfs(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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= 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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int t = 1;
vvi to;
vi d, f;
vector<bool> visited;

void dfs(int i) {
    i--;
    if (visited[i]) return;
    visited[i] = true;

    d[i] = t;
    t++;
    sort(ALL(to[i]));

    for (int nv : to[i]) {
        //debug(nv)
        
        dfs(nv);
    }
    
    f[i] = t;
    t++;
}
 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    to = vvi(N, vi());
    REP(i, N) {
        int k, idx;
        cin >> idx >> k;
        idx--;
        to[i].resize(k);
        REP(j, k) cin >> to[idx][j];
    }
    // debug(N)

    d.resize(N);
    f.resize(N);
    visited = vector<bool>(N, false);

    
    REP(i, N){
        if (f[i] == 0) dfs(i+1);
    } 

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

    return 0;
}

C++: /*
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

typedef vector<int> vi;

/* global variables */

vi nbrs[MAX_N];
int ds[MAX_N], fs[MAX_N];

/* subroutines */

int dfs(int u, int t) {
  ds[u] = ++t;

  for (int i = 0; i < nbrs[u].size(); i++) {
    int &v = nbrs[u][i];
    if (! ds[v]) t = dfs(v, t);
  }

  return (fs[u] = ++t);
}

/* main */

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    u--;

    for (int j = 0; j < k; j++) {
      int v;
      cin >> v;
      v--;
      nbrs[u].push_back(v);
    }
  }

  int t = 0;
  for (int i = 0; i < n; i++)
    if (! ds[i]) t = dfs(i, t);

  for (int i = 0; i < n; i++)
    printf("%d %d %d\n", i + 1, ds[i], fs[i]);

  return 0;
}

C++: #include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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

void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0) continue;
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++) color[u] = WHITE;
  tt=0;

  for(u=0;u<n;u++){
    if(color[u] == WHITE) dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,v,k,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j] = 0;
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();
  
  return 0;
}

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

using namespace std;

const int WHITE = 0, GREY = 1, BLACK = 2;

struct DFS {
    int n;
    vector<vector<int>> g;
    vector<int> color;
    int ct = 1; //current time
    vector<int> dt; //discover time
    vector<int> ft; //finish time
    
    DFS(int n) : n(n) {
        g.assign(n, vector<int>());
        color.assign(n, WHITE);
        dt.assign(n, -1);
        ft.assign(n, -1);
    }
    
    void addEdge(int u, int v) {
        g[u].push_back(v);
    }
    
    void dfs() {
        for (int i = 0; i < n; i++) {
            if (color[i] == WHITE) {
                dfsVisit(i);
            }
        }
    }
    
    void dfsVisit(int u) {
        //cout << "visited: " << u << endl;
        color[u] = GREY;
        dt[u] = ct++; //first assign ct to dt[u], then ++
        for (int v : g[u]) {
            if (color[v] == WHITE) {
                dfsVisit(v);
            }
        }
        color[u] = BLACK;
        ft[u] = ct++;
    }
    
    void printGraph() {
        for (int i = 0; i < n; i++) {
            cout << i << ": ";
            for (int j : g[i]) {
                cout << j << " ";
            }
            cout << endl;
        }
    }
    
    void printResults() {
        for (int i = 0; i < n; i++) {
            cout << i + 1 << " " << dt[i] << " " << ft[i] << endl;
        }
    }
};

int main() {
    int n;
    cin >> n;
    DFS dfs(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            dfs.addEdge(u - 1, v - 1);
        }
    }
    
    //dfs.printGraph();
    dfs.dfs();
    dfs.printResults();
    
    return 0;
}