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 <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const int MAX = 105;

int t = 0;
pair<int, int> ans[MAX];
bool seen[MAX];
vector<int> to[MAX];

void dfs(int u) {
  if (seen[u]) return;
  seen[u] = true;
  ans[u].first = ++t;
  for (int v: to[u]) {
    dfs(v);
  }
  ans[u].second = ++t;
}

int main() {
  int n, u, k, v;
  cin >> n;
  rep(i, n) {
    cin >> u >> k;
    rep(j, k) {
      cin >> v;
      to[u].push_back(v);
    }
  }

  rep(i, n+1) seen[i] = false;
  FOR(i, 1, n+1) sort(to[i].begin(), to[i].end());

  FOR(i, 1, n+1) dfs(i);

  FOR(i, 1, n+1) {
    cout << i << " " << ans[i].first << " " << ans[i].second << endl;
  }



  
  return 0;
}

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

int main()
{
 int i;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int c;
vector<int> E[SIZE];
int d[SIZE],f[SIZE]; //init:0

void dfs(int v){
  c++;
  d[v]=c;
  for(int to : E[v]) if(d[to] == 0){
    dfs(to);
  }
  c++;
  f[v] = c;
}

int n;

int main(){
  cin >> n;
  rep(i,0,n){
    int v,k;
    cin >> v >> k;
    rep(i,0,k){
      int u;
      cin >> u;
      //E[u].push_back(v);
      E[v].push_back(u);
    }
  }

  rep(i,0,n){
    if(d[i+1] ==0) dfs(i+1);
  };

  rep(i,0,n){
    cout << i+1 << " " <<  d[i+1] << " " << f[i+1] << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<vector>
#include<deque>
#include<tuple>
using namespace std;

int main(){
  vector <vector<int> > path_field;
  int n;

  cin >> n; n++;
  path_field.resize(n);
  for(int i=1;i<n;i++){
    path_field[i].resize(n);
    for(int j=1;j<n;j++){
      path_field[i][j]=0;
    }
  }
  for(int i=1;i<n;i++){
    int _m,m;

    cin >> _m >> m;
    for(int j=0;j<m;j++){
      int to;
      
      cin >> to;
      path_field[i][to]=1;
    }
  }

  vector <tuple<int,int> > ans;
  deque <int> stk;
  int sarched_point,sum=0;

  ans.resize(n);
  for(int i=1;i<n;i++){
    ans[i]=make_tuple(0,0);
  }
  for(int i_=1;i_<n;i_++){
    if(get<0>(ans[i_])==0){
      stk.push_back(i_);
      if(sum!=0) sum++;
    }
  
    while(!stk.empty()){
      sarched_point = stk.back();
      sum++;

      if(get<0>(ans[sarched_point])==0){
        get<0>(ans[sarched_point])=sum;
      }
      for(int i=1;i<n;i++){
        if((path_field[sarched_point][i]==1)&&(get<0>(ans[i])==0)){
          stk.push_back(i);
       	  break;
        }else if(i==(n-1)){
          get<1>(ans[sarched_point])=sum+1;
          stk.pop_back();
        }
      }
    }
  }

  for(int i=1;i<n;i++){
    cout << i << " " << get<0>(ans[i]) << " " << get<1>(ans[i]) << endl;
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

vector<int> *a;
bool *check;
int *d,*f;

int dfs(int u, int time){
    int i, v;
    check[u] = true;
    d[u] = time;
    time++;
    for(i=0;i<a[u].size();i++){
        v = a[u][i];
        if(!check[v])time = dfs(v,time);
    }
    f[u] = time;
    time++;
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    check = (bool *)malloc(sizeof(bool)*(n+1));
    d = (int *)malloc(sizeof(int)*(n+1));
    f = (int *)malloc(sizeof(int)*(n+1));
    for(i=0;i<=n;i++)check[i] = false;
    a = (vector<int> *)malloc(sizeof(vector<int>)*(n+1));

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

    int time = 1;
    for(i=1;i<=n;i++){
        if(!check[i])
        time = dfs(i,time);
    }

    for(i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],f[i]);

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD (int) 1e9+7

vector<int> E[200];
int d[200]={}, f[200]={};

int func(int pos, int time){
    if(d[pos]>0){
        return time;
    }
    d[pos] = time;
    time++;
    for (int to : E[pos]){
        time = func(to, time);
    }
    f[pos] = time;
    time++;
    return time;
}

int main(){
    int n;
    cin >> n;
    rep(i, n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            E[u].push_back(v);
        }
    }
    int time = 1;
    for (int i = 1; i <= n; i++){
        if(d[i]==0){
            time = func(i, time);
        }
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    // printf("%d\n", N);
    return 0;
}

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

int m[101][101];
int visit[101];
int d[101];
int f[101];
int n, t;

void dfs(int u){
  visit[u] = 1;
  d[u] = t;
  t++;
  
  for(int i = 0; i < n; ++i){
    if(m[u][i] == 1 && visit[i] == 0){
      dfs(i);
    }
  }

  f[u] = t;
  t++;
}

main()
{
  int u, k, v;
  t = 1;

  cin >> n;
  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;
    }
  }

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

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

  return (0);
}