Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	g := graph{}
	g.ee = make([]Edges, n)
	g.visited = make([]bool, n)
	g.found = make([]int, n)
	g.leave = make([]int, n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner) - 1
		k := getNextInt(scanner)
		for j := 0; j < k; j++ {
			v := getNextInt(scanner) - 1
			g.ee[u] = append(g.ee[u], Edge{
				to: v,
				id: u,
			})
		}
	}
	for i := 0; i < n; i++ {
		sort.Sort(g.ee[i])
	}
	for i := 0; i < n; i++ {
		if g.visited[i] {
			continue
		}
		g.dfs(i)
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", i+1, g.found[i], g.leave[i]))
	}
}

// Edge ...
type Edge struct {
	to, id int
}

type Edges []Edge

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

type graph struct {
	ee           []Edges
	t            int
	n            int
	visited      []bool
	found, leave []int
}

func (g *graph) dfs(i int) {
	g.visited[i] = true
	g.t++
	g.found[i] = g.t
	for _, e := range g.ee[i] {
		if g.visited[e.to] {
			continue
		}
		g.dfs(e.to)
	}
	g.t++
	g.leave[i] = g.t
}

C++: #include<iostream>
#include<vector>
#include<limits.h>
#include<stack>
#include<string>
using namespace std;

vector< vector<int> > L(105);
vector<int> d(105,0);
vector<int> f(105,0);
vector<bool> c(105,0);
int count=0;

int out(vector<int> &A){
	int n=A.size();
	int i;
	if (n==0){
		cout << "nothing" <<endl;
	}else if(n==1){
		cout << A[0] << endl;
	}else{
		for (i=0;i<=n-2;i++){
			cout << A[i] << " ";
		}
		cout << A[n-1] <<endl;
	}
}

void dfs (int v){
	if(c[v]) return ;
	count++;
	c[v]=1;
	d[v]=count;
	for (int i=0;i<L[v].size();i++){
		dfs(L[v][i]);
	}
	count++;
	f[v]=count;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,i,j;
	cin >> n;
	
	int id, deg, v;
	for (i=0;i<n;i++){
		cin >> id >> deg;
		for (j=0;j<deg;j++){
			cin >> v;
			L[id-1].push_back(v-1);
		}
	}
	for (i=0;i<n;i++){
		dfs(i);
	}
	for (i=1;i<n+1;i++){
		cout << i << " " << d[i-1] << " " << f[i-1] <<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int n, t;
vector<vector<int> > graph;
vector<int> d, f;
vector<bool> visited;

void dfs(int node){
    visited[node] = true;
    d[node] = t;
    t++;
    for(int i=0;i<int(graph[node].size());i++){
        int nxt = graph[node][i];
        if(!visited[nxt]){
            dfs(nxt);
        }
    }
    f[node] = t;
    t++;
}

int main(){
    cin >> n;
    graph.resize(n);
    d.resize(n);
    f.resize(n);
    visited.resize(n, false);
    for(int i=0;i<n;i++){
        int u, k;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            int v;
            cin >> v;
            graph[u-1].push_back(v-1);
        }
    }
    t = 1;
    for(int i=0;i<n;i++){
        if(!visited[i]){
            dfs(i);
        }
    }
    for(int i=0;i<n;i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<algorithm>
#include<stack>
#include<string.h>
using namespace std;
#define INFTY 2000000001
#define MAX 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n = 0;
int adl[MAX][MAX], deg[MAX];
int adm[MAX][MAX];
int color[MAX];
int d[MAX][2];
stack<int> depth;


void dfs() {
  int time = 1;
  for ( int i = 0; i < n; i++ ) {
    color[i] = WHITE;
  }
  depth.push(0);
  d[0][0] = time++;

  while (!depth.empty()) {
    int top = depth.top();

    int next;
    for (int i = 0; i < n; i++) {
      next = i;
      if (adm[top][i] == 1 && color[i] == WHITE) {
        depth.push(i);
        d[i][0] = time++;

        color[i] = GRAY;
        break;
      }
      next = n;
    }

    if (next == n) {
      color[top] = BLACK;
      d[top][1] = time++;
      depth.pop();
    }
  }
}

int main() {
  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      adm[i][j] = 0;
    }
  }
  for ( int i = 0; i < n; i++ ) {
    int num;
    scanf("%d", &num);
    num--;
    scanf("%d", &deg[num]);
    for ( int j = 0; j < deg[num]; j++) {
      scanf("%d", &adl[num][j]);
      adl[num][j]--;
      adm[num][adl[num][j]] = 1;
    }
  }

  dfs();

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



  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include<cstdio>

bool table[102][102] = {};
int color[102] = {}; //0:?????¢?´¢???1:?¨??????????, 2:??¢?´¢??????
int n, counter = 0;
int t_visit[102] = {};
int t_finish[102] = {};

void DFS(int y) {
	
	for (int j = 0; j <= n - 1;j++) {

		//?¨????or??¢?´¢???????????£???????????????
		if ((table[y][j] == 1)&&(color[j] == 0)) {
			color[y] = 1; //?¨???????????????????
			if (t_visit[y] == 0) t_visit[y] = ++counter;
			DFS(j);
		}

	}

	color[y] = 2; //??¢?´¢???????????????
	if (t_visit[y] == 0) t_visit[y] = ++counter;
	if (t_finish[y] == 0) t_finish[y] = ++counter;
	
}

int main(void) {
	int u, k, s;

	scanf("%d", &n);

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

	DFS(0);

	for (int i = 0; i <= n - 1;i++) {
		printf("%d %d %d\n", i + 1, t_visit[i], t_finish[i]);
	}

	return 0;
}