Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		u, k := sc.nextInt()-1, sc.nextInt()
		for j := 0; j < k; j++ {
			G[u] = append(G[u], sc.nextInt()-1)
		}
	}
	ans := make([][2]int, N)
	time := 0
	found := make(map[int]bool)
	var dfs func(cur int)
	dfs = func(cur int) {
		time++
		ans[cur][0] = time
		found[cur] = true
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !found[next] {
				dfs(G[cur][i])
			}
		}
		time++
		ans[cur][1] = time
	}
	for i := 0; i < N; i++ {
		if !found[i] {
			dfs(i)
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprint(wtr, i+1)
		for j := 0; j < 2; j++ {
			fmt.Fprint(wtr, " ")
			fmt.Fprint(wtr, ans[i][j])
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}

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();
}