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;

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

int N;
int G[MAX_N][MAX_N];
int color[MAX_N], d[MAX_N], f[MAX_N];
int t;

void bfs_visit(int u) {
    color[u] = GRAY;
    d[u] = ++t;
    for (int i = 0; i < N; i++) {
        if (G[u][i] && color[i] == WHITE) {
            bfs_visit(i);
        }
    }
    color[u] = BLACK;
    f[u] = ++t;
}

void dfs() {
    for (int i = 0; i < N; i++) {
        color[i] = WHITE;
    }
    t = 0;
    for (int i = 0; i < N; i++) {
        if (color[i] == WHITE) {
            bfs_visit(i);
        }
    }
    for (int i = 0; i < N; i++) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    cin >> N;
    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--;
            G[u][v] = 1;
        }
    }

    dfs();
    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> v(101);
int dp[101][2] = { 0 };
int n, t = 0;

void dfs(int a) {
	t++;
	if (dp[a][0] == 0) { dp[a][0] = t; }
	for (int i = 0;i < v[a].size();i++) {
		if (dp[v[a][i]][0] == 0) {
			dfs(v[a][i]);
		}
	}
	t++;
	if (dp[a][1] == 0) { dp[a][1] = t; }
}

int main() {
	cin >> n;
	for (int i = 0; i < n;i++) {
		int u,k; cin >> u >> k;
		for (int j = 0; j < k;j++) {
			int x; cin >> x;
			v[u].push_back(x);
		}
	}
	dfs(1);
	for (int i = 1; i <= n;i++) {
		cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

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

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

void visit(int a){
  int b;
  color[a]=GRAY;
  d[a]=++tt;
  for(b=0;b<n;b++){
    if(m[a][b]==0) continue;
    if(color[b]==WHITE) visit(b);
  }
  color[a]=BLACK;
  f[a]=++tt;
}

void dfs(){
  int a;
  for(a=0;a<n;a++) color[a]=WHITE;

  tt=0;

  for(a=0;a<n;a++){
    if(color[a]==WHITE) visit(a);
  }
  for(a=0;a<n;a++) printf("%d %d %d\n",a+1,d[a],f[a]);

}

int main(){
  int u,v,k,i,j;

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

  for(i=0;i<n;i++){
    cin >> u >> k;
    u--;
    for(j=0;j<k;j++){
      cin >> v;
      v--;
      m[u][v]=1;
    }
  }
  dfs();
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool graph[101][101];
int first_time[101],last_time[101];
int visited[101];
int tt=0;
int v[101][101];
#define white 0
#define gray 1
#define black 2//0回目の訪問、1回目の訪問、2回目の訪問の3種類あるからboolを使わない

void dfs(int v,int n) {
	for (int i = 2; i <= n; ++i) {
		if (graph[v][i] == false)continue;
		if (visited[i] == white) {
			visited[i] = gray;
			++tt;
			first_time[i] = tt;
			dfs(i, n);
		}
	}
	visited[v] = black;
	++tt;
	last_time[v] = tt;

}

int main() {
	int n;
	cin >> n;
	int u, k;
	for (int i = 0; i < n; ++i) {
		cin >> u >> k;
		for (int j = 0; j < k; ++j) {
			cin >> v[u][j + 1];
			graph[u][v[u][j + 1]] = true;
		}
	}
	for (int i = 1; i <= n; ++i) {//1つの始点から全訪問可能とは限らないから
		if (visited[i] == white) {
			visited[i] = gray;
			++tt;
			first_time[i] = tt;
			dfs(i, n);
		}
	}
	for (int i = 1; i <= n; ++i) {
		cout << i << " " << first_time[i] << " " << last_time[i] << endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAX_NODE 101

int begin_times[MAX_NODE];
int end_times[MAX_NODE];
int c_time=0;
queue<int> g[MAX_NODE];

void dfs(int f){
  if(begin_times[f]>0)return;
  c_time++;
  begin_times[f]=c_time;
  while( !g[f].empty() ){
    int to = g[f].front();
    g[f].pop();
    if(end_times[to]>0)continue;
    dfs(to);
  }
  c_time++;
  end_times[f]=c_time;
}

int main(){
  int n;cin>>n;
  rep(i, n){
    int from;
    int count;
    cin>>from>>count;
    rep(j, count){
      int t;cin>>t;
      g[from].push(t);
    }
  }

  rep1(i, n)dfs(i);

  rep1(i, n){
    cout<<i<<' '<<begin_times[i]<<' '<<end_times[i]<<endl;
  }

  return 0;
}