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<stdio.h>
#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 dfs_visit(int u) {
  int v;
  color[u] = GRAY;
  d[u] = ++tt;  // 最初の訪問
  for ( 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() {
  int u;
  // 初期化
  for ( u = 0; u < n; u++ ) color[u] = WHITE;
  tt = 0;

  for ( u = 0; u < n; u++ )
    // 未訪問の u を始点として深さ優先探索
    if ( color[u] == WHITE ) dfs_visit(u);
  for ( u = 0; u < n; u++ )
    printf("%d %d %d\n", u + 1, d[u], f[u]);
}

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

  scanf("%d", &n);
  for ( i = 0; i < n; i++ )
    for ( j = 0; j < n; j++ ) M[i][j] = 0;

  for ( i = 0; i < n; i++ ) {
    scanf("%d %d", &u, &k);
    u--;
    for ( j = 0; j < k; j++ ) {
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define N 100
int M[N][N],n;
int color[N],d[N],f[N],tt;
void dfs_visit(int u)
{
  int v;
  color [u] = GRAY ;
  d[u] = ++tt;
  for(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()
{
  int u ;
  for(u = 0;u<n;u++)
    color[u] = WHITE ;
  tt = 0;
  for(u = 0;u<n;u++)
  {
    if(color [u] == WHITE )
      dfs_visit(u);
  }
  for(u = 0;u<n;u++)
    {
      printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}
int main ()
{
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i = 0;i<n;i++)
   {
     for(j = 0;j<n;j++)
        M[i][j] = 0;
   }
  for(i = 0;i<n;i++)
  {
    scanf("%d %d",&u,&k);
    u--;
    for(i = 0;j<k;j++)
      {
        scanf("%d",&v);
        v--;
        M[u][v] =1;
      }
  }
  dfs();
  return  0 ;
}

C++: #include<bits/stdc++.h>
#define N 105
using namespace std;
int n,u,k,v,e[N][N],cnt;
int ans1[N],ans2[N];
bool used[N];
 
void dfs(int x){
  if(used[x])return;
  used[x]=true;
  ans1[x]=cnt++;
  for(int i=0;i<n;i++)
    if(e[x][i])dfs(i);
  ans2[x]=cnt++;
}
 
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      e[u-1][v-1]=1;
    }
  }
  cnt=1;
  for(int i=0;i<n;i++)
    if(!used[i])dfs(i);
  
  for(int i=0;i<n;i++)
    cout<<i+1<<' '<<ans1[i]<<' '<<ans2[i]<<endl;

  return 0;
}

C++: #include<iostream>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 1

int n, M[N][N];
int color[N], s[N], f[N], ts; 

void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    s[u] = ++ts;
    for (v=0; v<n; v++) {
        if(M[u][v]==0){
            continue;
        }
        if (color[v]==WHITE) {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++ts;
}

void dfs() {
    int u;
    for (u=0; u<n; u++) {
        color[u] = WHITE;
    }
    ts = 0;
    //for (u=0; u<n; u++) {
    //    if (color[u]==WHITE){
            dfs_visit(0);
    //    }
    //}
    for (u=0; u<n; u++) {
        printf("%d %d %d\n", u+1, s[u], f[u]);
    }
}

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

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A
// Graph I - Depth First Search

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <cstring>
#include <climits>
#include <memory>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const ui64 MAX_N = 100;

enum class color_type {
    white,
    gray,
    black
};

int adj[MAX_N][MAX_N];
color_type color[MAX_N];
int find_time[MAX_N];
int complete_time[MAX_N];
int n;
int curr_time;

void dfs(int u) {
    curr_time++;
    color[u] = color_type::gray;
    find_time[u] = curr_time;

    // search adj nodes
    for (int v = 0; v < n; ++v) {
        if (adj[u][v] != 0 && color[v] == color_type::white) dfs(v);
    }
    curr_time++;
    color[u] = color_type::black;
    complete_time[u] = curr_time;
}

void run_dfs() {
    for (int v = 0; v < n; ++v) {
        color[v] = color_type::white;
        find_time[v] = 0;
        complete_time[v] = 0;
    }

    curr_time = 0;
    for (int v = 0; v < n; ++v) {
        if (color[v] == color_type::white) dfs(v);
    }
}

int main() {
    memset(adj, 0, sizeof(adj));
    cin >> n;

    int u, degree;
    for (int i = 0; i < n; ++i) {
        cin >> u >> degree;
        u--; // 0-origin

        int v;
        for (int j = 0; j < degree; ++j) {
            cin >> v;
            v--; //0-origin
            adj[u][v] = 1;
        }
    }

    run_dfs();
    for (int i = 0; i < n; ++i) cout << i + 1 << " " << find_time[i] << " " << complete_time[i] << endl;
    return 0;
}