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<stdio.h>
#define MAX 101

int G[MAX][MAX], d[MAX], f[MAX];

void adjacency_matrices(int n) {
    int i, j, u, m, k;

    for (i=1; i<=n; i++) {
        scanf("%d", &u);
        scanf("%d", &m);
        for (j=1; j<=m; j++) {
            scanf("%d", &k);
            G[u][k] = 1;
        }
    }
}

int depth_first_search(int t, int i, int n) {
    int j;
    bool get;
    d[i] = t;

    for (j=1; j<=n; j++) {
        if (G[i][j]==1 && d[j]==-1) {
            t = depth_first_search(++t, j, n);
        } 
    }

    f[i] = ++t;

    return t;
}

int main() {
    int n, i, j, t;
    t = 0; 

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

    adjacency_matrices(n);

    for (i=1; i<=n; i++) {
        if (f[i]==-1) {
            t = depth_first_search(++t, i, n);
        }
    }

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

    return 0;
}

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

using namespace std;

static const int N = 100;
int n, m[N][N];
int time, begT[N], endT[N];
bool visited[N];

int nxt(int u)
{
	for (int v = 0; v < n; ++v)
	{
		if (m[u][v] > 0 && !visited[v]) return v;
	}
	return -1;
}

void dfs_helper(int idx)
{
	stack<int> s;
	s.push(idx);
	begT[idx] = time++;
	visited[idx] = true;

	while (!s.empty())
	{
		int u = s.top();
		int v = nxt(u);
		if (-1 == v)
		{
			s.pop();
			endT[u] = time++;
			continue;
		}
		s.push(v);
		begT[v] = time++;
		visited[v] = true;
	}
}

void dfs()
{
	time = 1;

	for (int i = 0; i < n; ++i)
	{
		if (!visited[i]) dfs_helper(i);
	}

	for (int i = 0; i < n; ++i)
	{
		cout << i + 1 << " " << begT[i] << " " << endT[i] << endl;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i)	{
		for (int j = 0; j < n; ++j)	{
			m[i][j] = 0;
		}
	}

	for (int i = 0; i < n; ++i)
		visited[i] = false;

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

	dfs();

	return 0;
}

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

#define WHITE 0
#define GRAY 1
#define BLACK 2

int G[101][101];
int color[101];
int n;
int d[101], f[101], t;

void search_loop(int i)
{
	int next;
	d[i] = ++t;
	color[i] = GRAY;

	for(next = 1; next <= n; next++){
		if(i == next && G[i][i] > 0) break;
		if(G[i][next] > 0 && color[next] != BLACK){
			search_loop(next);
		}
	}
	f[i] = ++t;
	color[i] = BLACK;

	return;
}

void dfs()
{
	int i;
	for(i = 1; i <= n; i++) color[i] = WHITE;  // initialize.

	t = 0;
	for(i = 1; i <= n; i++){
		if(color[i] == WHITE) search_loop(i);
	}
	for(i = 1; i <= n; i++){
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return ;
}

int main()
{
	int i, j, k, e;
	cin >> n;
	for(i = 1; i <= n; i++){
		for(j = 1; j <= n; j++){
			G[i][j] = 0;
		}
	}
	do{
		cin >> i >> e;
		for(j = 1; j <= e; j++){
			cin >> k;
			G[i][k] = 1;
		}
	}while(i < n);

	dfs();

	return 0;
}

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

using namespace std;

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

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

    for (int i = 0; i < k; i++) {
      int v;
      cin >> v;
      --v;

      adjacent[u].push_back(v);
    }
  }

  vector<int> d(n, 0), f(n, 0);
  vector<bool> visited(n, false);
  stack<int> S;

  S.push(0);

  int t = 1;

  d[0] = t;

  while (!S.empty()) {
    ++t;

    int u = S.top();

    if (!visited[u]) {
      visited[u] = true;
    }

    bool done = true;
    for (int i = 0; i < adjacent[u].size(); i++) {
      int v = adjacent[u][i];

      if (!visited[v]) {
        done = false;
        d[v] = t;
        S.push(v);
        break;
      }
    }

    if (done) {
      f[u] = t;
      S.pop();
    }

    // スタックが空になった後、未訪問なノードがあればそれを始点として再度DFSする
    if (S.empty()) {
      for (int i = 0; i < n; i++) {
        if (!visited[i]) {
          ++t;
          S.push(i);
          d[i] = t;
          break;
        }
      }
    }
  }

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

  return 0;
}

/*
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0
*/