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 <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int t = 0;
vector<vector<int> > a;
vector<int> d, f;
vector<bool> v;

void dfs(int i) {
  v[i] = true;
  d[i] = ++t;
  for (int j : a[i]) {
    if (!v[j]) {
      dfs(j);
    }
  }
  f[i] = ++t;
}

int main() {
    int n; cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        int u; cin >> u; u--;
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int v; cin >> v; v--;
            a[i].push_back(v);
        }

    }
    v.resize(n, false);
    d.resize(n);
    f.resize(n);

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

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <list>
#define black 0
#define red 1
#define white -1
#define maxn 110
using namespace std;

int tot = 0;
int book[maxn] = {}, t[maxn][2] = {};
list<int> map[maxn];

void dfs(int u)
{
	book[u] = red;
			t[u][0] = ++tot;
			for (list<int>::iterator it = map[u].begin(); it != map[u].end(); it++)
			{
				if (book[*it - 1] == black)
				{
					dfs(*it - 1);
				}
			}
			book[u] = white;
			t[u][1] = ++tot;
	return;
}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int u, k, v;
		scanf("%d%d", &u, &k);
		u--;
		for (int i = 0; i < k; i++)
		{
			scanf("%d", &v);
			map[u].push_back(v);
		}
	}
	for (int i = 0; i < n; i++)
		if (book[i] == black)
			dfs(i);
	for (int i = 0; i < n; i++)
	{
		printf("%d %d %d\n", i + 1, t[i][0], t[i][1]);;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x)
#define CMIN(m, x)  m = min(m,x)
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;

int cnt = 0;
void dfs(int i,vector<vector<int>> &g, vector<vector<int>> &ans){
    if(ans[i][0] == 0){
        cnt++; 
        ans[i][0] = cnt;
        REP(j,g[i].size()){
            dfs(g[i][j] - 1,g,ans);  
        }
        cnt++;

        ans[i][1] = cnt;
    }
}
int main(){
    int n;
    cin >> n;
    int u,k;
    vector<vector<int>> g(n);
    vector<vector<int>> ans(n,vector<int>(2,0));
    REP(i,n){
        cin >> u >> k;
        g[u - 1] = vector<int>(k);
        REP(j,k)
            cin >> g[u - 1][j];
    }
    REP(i,n)
        dfs(i,g,ans);
    REP(i,n){
        printf("%d %d %d\n",i + 1, ans[i][0],ans[i][1]);
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;
#define MAX 100000

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

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

int next(int u){
  for(int v=nt[u];v<n;v++){
    nt[u]=v+1;
    if(M[u][v]) return v;
  }
  return -1;
}

void dfs_visit(int r){
  for(int i=0;i<n;i++) nt[i]=0;
  stack<int> S;
  S.push(r);
  color[r]=GRAY;
  d[r]=++tt;
  while( !S.empty() ){
    int u=S.top();
    int v=next(u);
    if(v!=-1){
      if(color[v]==WHITE){
        color[v]=GRAY;
        d[v]=++tt;
        S.push(v);
      }
      else{
        S.pop();
        color[u]=BLACK;
        f[u]=++tt;
      }
    }
  }
}

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

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

int main(){
  int u,k,v;
  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++){
    cin >> u >> k;
    u--;
    for(int j=0;j<k;j++){
      cin >> v;
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}

C++: #include <stdio.h>

int A[101][101];
int ans[101][3];
int an = 1;


int judge(int i, int j){
  if(ans[i][j] == 0){
    ans[i][j] = an;
    an++;
  }
}

int serch(int a[101][101], int  ni, int n){
  int  j;
  
  for(j=0; j<n; j++){
    if(A[ni][j] == 1){
      judge(j, 1);
      serch(A, j, n);
    }
  }
  judge(ni, 2);
}

int  main(){
  int i, j, k, n, x, y;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    for(j=0; j<n; j++)
      A[i][j] = 0;
    ans[i][0] = i+1;
  }
  
  for(i=0; i<n; i++){
    scanf("%d %d", &x, &y);
    for(j=0; j<y; j++){
      scanf("%d", &k);
      A[i][k-1] = 1;
    }
  }
  
  for(j=0; j<n; j++){
  judge(j,1);
    for(i=0; i<n; i++){
      if(A[j][i] == 1){
        judge(i, 1);
        serch(A, i, n);
      }
    }
  judge(j, 2);
  }
  
  for(i=0; i<n; i++){
    for(j=0; j<3; j++){
      if(j>0)
        printf(" ");
      printf("%d", ans[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}