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>
using namespace std;

# define WHITE 0
# define GREY  1
# define BLACK 2

int M[100][100];
int color[100], d[100], f[100];
int n, tt = 0;

void dfs_visit(int u) {
	color[u] = GREY;
	d[u] = ++tt;
	for (int 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() {
    for (int i = 0; i < n; i++) color[i] = WHITE;
	for (int i = 0; i < n; i++) {
	    if ( color[i] == WHITE ) dfs_visit(i);
	}
}

int main() {
    int u, v, k;
	scanf("%d", &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++) {
		scanf("%d %d", &u, &k);
		u--;
		for (int j = 0; j < k; j++) {
			scanf("%d", &v);
			v--;
			M[u][v]++;
		}
	}
	dfs();
	for (u = 0; u < n; u++) {
	    printf("%d %d %d\n", u+1, d[u], f[u]);
	}
	return 0;
}

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

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

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

    int M[N][N];
    int D[N], F[N], C[N];

    for (int i = 0; i < N; i++)
    {
        D[i] = 0;
        F[i] = 0;
        C[i] = WHITE;
        
        for (int j = 0; j < N; j++)
        {
            M[i][j] = 0;
        }
    }

    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--;
            M[u][v] = 1;
        }
    }

/*
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (j > 0)
                cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
*/
    stack<int> *S = new stack<int>;

    int time = 0;

    S->push(0);
    C[0] = GRAY;
    D[0] = ++time;

    while (S->size() > 0)
    {
        int u = S->top();
        int v = -1;

        // next 
        for (int i = 0; i < N; i++)
        {
            int flag = M[u][i];

            if (flag == 1)
            {
                if (C[i] == WHITE)
                {
                    v = i;
                }
            }
        }

        if (v != -1)
        {
            C[v] = GRAY;
            D[v] = ++time;
            S->push(v);
        }
        else
        {
            S->pop();
            C[u] = BLACK;
            F[u] = ++time;
        }
    }

    for (int i = 0; i < N; i++)
    {
        cout << i + 1 << " " << D[i] << " " << F[i] << endl;
    }
    return 0;
}

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

using namespace std;

/*****************************************/
/*         Function prototype            */
/*****************************************/

vector<vector<int> > list_to_mat(vector<vector<int> >& adj);
void dump_mat( vector<vector<int> >& mat);
void dfs(vector<vector<int> >& adj_list, int now, vector<int>& d, vector<int>& f, int *t);

/*****************************************/
/*            Main Function              */
/*****************************************/


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

  vector<vector<int> > list(n+1);
  for(int i=0; i<n; i++){
    int u,k; cin >> u >> k;
    vector<int> tmp(k);
    for(int j=0; j<k; j++) cin >> tmp[j];
    sort(tmp.begin(),tmp.end());
    list[u] = tmp;
  }
  int t=1;
  vector<int> d(n+1,-1);
  vector<int> f(n+1,-1);

  dfs(list,1,d,f,&t);

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



/*****************************************/
/*            Implimentation             */
/*****************************************/


void dfs(vector<vector<int> >& adj_list, int now, vector<int>& d, vector<int>& f, int* t){
  d[now] = *t;
  (*t)++;
  
  for(auto v : adj_list[now]){
    if(d[v] != -1) continue;
    dfs(adj_list, v, d, f, t);
  }
  f[now] = *t;
  (*t)++;
  return ;
}


vector<vector<int> > list_to_mat(vector<vector<int> >& adj){
  const int mat_size = (int)adj.size();
  vector<vector<int> > ans(mat_size,vector<int>(mat_size,0));
  for(int i=0; i<mat_size; i++){
    for(int j=0; j<adj[i].size(); j++){
      ans[i][adj[i][j]-1] = 1;
    }
  }
  return ans;
}


void dump_mat( vector<vector<int> >& mat){
  
  const int mat_size = (int)mat.size();
  for(int i=0; i<mat_size; i++){
    for(int j=0; j<mat[i].size(); j++){
      cout << mat[i][j];
      if(j!=mat[i].size()-1)
	cout << " ";
      else
	cout << "\n";
    }
  }
}

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


using namespace std;

int n;
vector< vector<int> > edges(100);
int t;
vector< pair<int,int> > ans(100);
vector< bool > vis(100, false);

void dfs(int v){
  t++;
  vis[v] = true;
  ans[v].first = t;
  for(int i : edges[v])
    if(vis[i] == false)
      dfs(i);
  t++;
  ans[v].second = t;
}

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

  for(int i = 0; i < n; i++){
    int k;
    cin >> k >> k;
    for(int j = 0; j < k; j++){
      int to;
      cin >> to;
      edges[i].push_back(to-1);
    }
  }

  t = 0;
  dfs(0);
  for(int i = 0; i < n; i++){
    cout << i + 1 << ' ' <<  ans[i].first << ' ' << ans[i].second << endl;
  }
}