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 <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int MAX_N = 150;
int G[MAX_N][MAX_N], found[MAX_N], finished[MAX_N];
int Time, N;
void dfs(int u)
{
    Time++;
    found[u] = Time;
    for(int nextV = 1; nextV <= N; nextV++)
    {
        if(found[nextV] || G[u][nextV] == 0) continue;
        dfs(nextV);
    }
    Time++;
    finished[u] = Time;
}
void init()
{
    Time = 0;
    for(int i = 0; i <= N; i++)
    {
        found[i] = 0;
        finished[i] = 0;
    }
    for(int i = 0; i <= N; i++) for(int j = 0; j <= N; j++) G[i][j] = 0;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    init();
    for(int i = 0; i < N; i++)
    {
        int u, k; cin >> u >> k;
        for(int j = 0; j < k; j++)
        {
            int v; cin >> v;
            G[u][v] = 1;
        }
    }
    int u = 1;
    while(u <= N)
    {
        if(found[u] == 0) dfs(u);
        u++;
    }
    for(int v = 1; v <= N; v++)
    {
        cout << v << " " << found[v] << " " << finished[v] << endl;
    }
    return 0;
}

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

void solve(){
  int n; cin >> n;
  vector<vector<int> > v(n + 1, vector<int>(n + 1, 0));
  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][x] = 1;
    }
  }
  vector<int> d(n + 1), f(n + 1), c(n + 1, 0);
  stack<int> s;
  int t = 0;
  for(int j = 1; j <= n; j++){
    if(c[j] == 0){
      s.push(j);
      d[j] = ++t;
      c[j] = 1;
      while(s.size() != 0){
        t++;
        int x = s.top();
        int i;
        for(i = 1; i <= n; i++){
          if(v[x][i] == 1 && c[i] == 0){
            d[i] = t;
            c[i] = 1;
            s.push(i);
            break;
          }
        }
        if(i == n + 1){
          f[x] = t;
          s.pop();
        }
      }
    }
  }
  for(int i = 1; i <= n; i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
  return;
}

int main(){
  solve();
  return 0;
}

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

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],sta[N],fin[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;
  sta[r]= ++tt;

  while(!s.empty()) //空じゃない間
  {
    int u=s.top();
    int v= next(u);
    if(v != -1)
    {
      if(color[v]==white)
      {
        color[v]=gray;
        sta[v]= ++tt;
        s.push(v);
      }
    }
    else //v=-1
    {
      s.pop();
      color[u]=black;
      fin[u]= ++tt;
    }
  }
}

void dfs()
{
  //初期化
  for(int i=0;i<n;i++)
  {
    color[i]=white;
    nt[i]=0;
  }
  tt=0;

  //未訪問のuを始点としてdfsする
  for(int u=0;u<n;u++)
  {
    if(color[u]==white) dfs_visit(u);
  }
  for(int i=0;i<n;i++)
  {
    cout<<i+1<<" "<<sta[i]<<" "<<fin[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; //辺があれば1と定義される
    }
  }

  dfs();
}