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>
using namespace std;
int d[105]={0},f[105]={0};
bool vi[105]={0};
int Time=0;
int k[105][105];

void dfs(int r,int n){

	vi[r]=true;
	d[r]=Time;
for(int i=0;i<n;i++){
	if(vi[i]!=true && k[r][i]==1){
		Time=Time+1;
		d[i]=Time;
		dfs(i,n);
		f[i]=Time;
	}
}
Time=Time+1;
f[r]=Time;
}
int main() {
int n,l,a,b;
cin>>n;
for(int j=0;j<n;j++){
	cin>>l>>a;
	for(int i=0;i<a;i++){
		cin>>b;
		k[j][b-1]=1;
	}
}
for(int g=0;g<n;g++){
	if(vi[g]!=true){
		Time=Time+1;
		dfs(g,n);
	}
	
}
for(int k=0;k<n;k++){

cout<<k+1<<" "<<d[k]<<" "<<f[k]<<endl;
}	
	return 0;
}

C++: 6
1 2 2 4
2 1 5
3 2 5 6
4 0
5 1 4
6 1 6

C++: #include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>

const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

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

int Next(int node_id)
{
    for (int i = 0; i < n; i++) {
        if (adj_mat[node_id][i] == 1 && color[i] == WHITE) {
            return i;
        }
    }
    return -1;
}

void DFS(int node_id)
{
    std::stack<int> S;
    S.push(node_id);
    color[node_id] = GRAY;
    d[node_id] = tt++;

    while(!S.empty()) {
        int target = S.top();
        int next = Next(target);
        if (next != -1) {
            color[next] = GRAY;
            d[next] = tt++;
            S.push(next);
        } else {
            S.pop();
            color[target] = BLACK;
            f[target] = tt++;
        }
    }
}

void Init(int n)
{
    tt = 1;
    for (int i = 0; i < n; i++) {
        d[i] = 0;
        f[i] = 0;
        color[i] = WHITE;
        for (int j = 0; j < n; j++) {
            adj_mat[i][j] = 0;
        }
    }
}

int main(int argc, char *argv[])
{
    scanf("%d", &n);

    Init(n);    

    // make adj matrix
    for (int i = 0; i < n; i++) {
        int node_id, adj_num;;
        scanf("%d", &node_id);
        scanf("%d", &adj_num);
        node_id--;
        for (int j = 0; j < adj_num; j++) {
            int adj_id;
            scanf("%d", &adj_id);
            adj_id--;
            adj_mat[node_id][adj_id] = 1;
        }
    }

    // depth search
    for (int i = 0; i < n; i++) {
        if (color[i] == WHITE) DFS(i);
    }

    // dump adj matrix
    for (int i = 0; i < n; i++) {
        fprintf(stdout, "%d %d %d\n", i+1, d[i], f[i]);
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
typedef long long ll;
#define int ll

int g[105][105], d[105], f[105];
int presenttime = 1, n;
bool is_search[105];

void dfs(int p) {
  d[p] = presenttime++;
  is_search[p] = true; // ??????????????§?????§??????

  for (int i = 0; i < n; i++) {
    if(is_search[i] == false && g[p][i] && p != i) dfs(i);
  }
  if (f[p] == 0) f[p] = presenttime++;
}

signed main(void) {
  int u, k, v;

  fill(is_search, is_search + n, false);

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int i = 0; i < k; i++) {
      cin >> v;
      g[u-1][v-1] = 1;
    }
   }

  int s = 0, i;

   while(1) {
    dfs(s);

    for (i = 0; i < n; i++) {
      if (is_search[i] == false) {
        s = i;
        break;
      }
    }
    if(i == n) break;
   }

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

C++: #include<iostream>

using namespace std;

const int MAX = 100;

void search(bool graph[MAX][MAX], int find[], int done[], int n, int u,int& count) {
	count++;
	find[u] = count;
	for (int i = 0; i < n; i++) {
		if (graph[u][i] && find[i] == 0) {
			search(graph, find, done, n, i, count);
		}
	}
	count++;
	done[u] = count;
}

int main() {
	bool check[MAX] = { false };
	int find[MAX] = { 0 };
	int done[MAX] = { 0 };
	bool graph[MAX][MAX] = { {false} };
	int N;

	cin >> N;
	for (int i = 0; i < N; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int temp;
			cin >> temp;
			graph[u - 1][temp - 1] = true;
		}
	}

	int count = 0;
	for (int i = 0; i < N; i++) {
		if (find[i] == 0) {
			search(graph, find, done, N, 0, count);
		}
	}

	for (int i = 0; i < N; i++) {
		cout << i + 1 << " " << find[i] << " " << done[i] << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fi first
#define se second
using Graph=vector<vector<int>>;

void dfs(int s,Graph graph,vector<int> &d,vector<int> &f,int &flag1,int &flag2)
{
	int n=graph.size();
	d[s]=flag1;
	flag1++;
	for (int i=0;i<n;i++)
	{
		if (graph[s][i]==1 && d[i]==-1) dfs(i,graph,d,f,flag1,flag2);
	}
	f[s]=flag2;
	flag2++;
}
int main()
{
	int n;cin >> n;
	Graph graph(n,vector<int> (n,0));
	int u,k,v;
	for (int i=0;i<n;i++)
	{
		cin >>u;
		cin >>k;
		for (int j=0;j<k;j++)
		{
			cin >>v;
			graph[u-1][v-1]=1;
		}
	}
	int flag1=1,flag2=1;
	vector<int> d(n,-1),f(n-1);
	for (int i=0;i<n;i++)
	{
		if (d[i]==-1) dfs(i,graph,d,f,flag1,flag1);
	}
	
	for (int i=0;i<n;i++)
	{
		cout <<i+1 <<" " << d[i] <<" " << f[i] << endl;
	}
	return 0;
}