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 <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
const int INF = 0x7fffffff;

int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}

using Graph = vector<vector<int>>;

int g[101][101];
int seen[101];
int stamp[2][101];
int n;
int t;

void dfs(int v){
  seen[v] = 1;
  int ii;

  //cout << v << endl;
  
  stamp[0][v] = t;
  t++;

  //for(ii=1;ii<=n;ii++){
  //  cout << seen[ii] << endl;
  //}
  
  for(ii=1;ii<=n;ii++){
    //cout << "v:"<< v << "ii:" << ii << " " << g[v][ii] << endl;

    if(seen[ii] == 1){continue;}
    //cout << "v:"<< v << "ii:" << ii << " " << g[v][ii] << endl;

    if(g[v][ii] == 1){
      dfs(ii);
    }
  }
  
  stamp[1][v] = t;
  t++;
}

int main(){
  long ii,jj,kk;
  vector<int> a;


  memset(g,0,sizeof(g));

  memset(stamp,0,sizeof(stamp));
  
  cin >> n;

  int v,vn,r;
  
  for(ii=0;ii<n;ii++){
    cin >> v;
    cin >> vn;
    for(jj=0;jj<vn;jj++){
      cin >> r;
      g[v][r] = 1;
    }
  }

  //for(ii=1;ii<=n;ii++){
  //  for(jj=1;jj<=n;jj++){
  //    cout << g[ii][jj] ;
  //    if(jj!=n){
  //      cout << " ";
  //    }
  //  }
  //  cout << endl;
  //}  
  
  t = 1;
  memset(seen,0,sizeof(seen));

  for(ii=1;ii<=n;ii++){
    if(seen[ii] == 0){
      dfs(ii);
    }

  }


  for(ii=1;ii<=n;ii++){
    cout << ii << " " << stamp[0][ii] << " " << stamp[1][ii] << endl;
  }
  return 0;
}

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

int main() {
    int n;
    cin >> n;

    vector<vector<int>> edge(n);
    for (int i = 0; i < n; i++) {
        int m, c;
        cin >> m >> c;
        for (int j = 0; j < c; j++) {
            int x;
            cin >> x;
            edge[i].push_back(--x);
        }
    }

    int timestamp = 1;
    vector <int> d(n, -1), f(n, -1);
    auto dfs = [&](auto dfs, int cur) -> void {
        d[cur] = timestamp++;
        for (int ch : edge[cur]) {
            if (d[ch] == -1) {
                dfs(dfs, ch);
            }
        }
        f[cur] = timestamp++;
    };

    for (int i = 0; i < n; i++) {
        if (d[i] == -1) {
            dfs(dfs, i);
        }
    }

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

    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
bool visit[100];
int finish_time[100];
int find_time[100];
int t;
vector<int> E[100];
void dfs(int u){
  visit[u] = true;
  find_time[u] = ++t;
  for(int v : E[u]) if(!visit[v]) dfs(v);
  finish_time[u] = ++t;
}

int main(){
  int n;
  cin >> n;
  rep(i,n){
    int u,k;
    cin >> u >> k;
    u--;
    rep(j,k){
      int v;
      cin >> v;
      v--;
      E[u].push_back(v);
    }
  }
  rep(i,n) if(!visit[i]) dfs(i);
  rep(i,n){
    cout << i+1 << " " << find_time[i] << " " << finish_time[i] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

bool graph[100][100]={false};
int d[100],f[100];
bool visited[100]={false};
int t=0;
void dfs(int gsize,int now){
    if(visited[now]==false)d[now]=++t;
    visited[now]=true;

    for(int i=0;i<gsize;i++){
        if(graph[now][i]==true && visited[i]==false){
            dfs(gsize,i);
        }
    }
    f[now]=++t;
}
int main(void){
    int n;
    cin>>n;
    rep(i,0,n){
        int u,k;
        cin>>u>>k;
        u--;
        rep(j,0,k){
            int v;
            cin>>v;
            v--;
            graph[u][v]=true;
        }
    }
    rep(i,0,n){
        if(visited[i]==false)
            dfs(n,i);
    }
    rep(i,0,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    return 0;
}

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

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int mat[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]+=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(mat[dst][cur]==1&&c[dst]==0){
			dfs(dst);
		}
	}
	t += 1; 
	mytime2[cur]=t;
}


int main()
{
	vector<int> v[110];
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int tmp;
			cin>>tmp;
			v[u].push_back(tmp);
		}
	}
	for(int i=0;i<100;i++){
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			mat[i][j]=0;
		}
	}
	for(int i=1;i<n+1;i++){
		for(int j=0;j<v[i].size();j++){
			mat[i-1][v[i][j]-1]=1; //
		}
	}
	for(int i=0;i<n;i++){
    if(c[i]!=1){
      dfs(i);
    }
  }
  for(int i=0;i<n;i++)
    {
      cout<<(i+1)<<' '<<mytime1[i]<<' '<<mytime2[i]<<endl;
    }
}