Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

vector<int>visited;
vector<int>d,f;
int cnt;

void dfs(int v,vector<vector<int>> &g){
  if(!visited[v])visited[v]=1,d[v]=++cnt;
  for(auto x:g[v]){
    if(visited[x]==0){
      dfs(x,g);
    }
  }
  visited[v]=2;
  f[v]=++cnt;
}

void solve(){
  int n;
  cin>>n;
  cnt=0;
  visited.resize(n);
  d.resize(n);f.resize(n);
  vector<vector<int>>g(n);
  rep(i,n){
    int u;
    cin>>u;
    u--;
    int k;
    cin>>k;
    int v;
    rep(j,k){
      cin>>v;
      v--;
      g[u].pb(v);
    }
  }
  rep(i,n){
    if(!visited[i])dfs(i,g);
  }
  rep(i,n){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<"\n";
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define MAX 101

int n;
Graph G(MAX);
vector<bool> seen(MAX, false);
vector<int> d(MAX), f(MAX);
int timer = 1;

void dfs(const Graph &G, int v)
{
  seen.at(v) = true;
  d.at(v) = timer++;
  int next_v;
  for (int i = 0; i < G.at(v).size(); i++)
  {
    next_v = G.at(v).at(i);
    if (seen.at(next_v))
    {
      continue;
    }
    dfs(G, next_v);
  }
  f.at(v) = timer++;
}

int main()
{
  cin >> n;
  int k, u, v;
  for (int i = 0; i < n; i++)
  {
    cin >> u >> k;
    for (int j = 0; j < k; j++)
    {
      cin >> v;
      G.at(u).push_back(v);
    }
  }
  for (int v = 1; v <= n; v++)
  {
    if (seen.at(v))
    {
      continue;
    }
    dfs(G, v);
  }
  for (int i = 1; i <= n; i++)
  {
    cout << i << " " << d.at(i) << " " << f.at(i) << endl;
  }
}

C++: #include <iostream>
#include <string>

using namespace std;

int n;
vector<vector<int>> g; 
int time = 0;
int timeT = 0;
vector<int> d, f;
 
void dfs(int node){
    timeT++;

    if(d[node] == 0){
        d[node] = timeT;
    }

    for(auto next : g[node]){
        if(d[next] == 0){
            dfs(next);
        }
    }
    
    timeT++;
    if(f[node] == 0){
        f[node] = timeT;
    }
    return;
}
    
int main(){
    
    cin >> n;

    d.assign(n + 1, 0);
    f.assign(n + 1, 0);

    g.assign(n + 1, vector<int>());

    for(int i = 0; i < n; i++)
    {
        int nod, numOut;
        cin  >> nod >> numOut;
        for(int j = 0; j < numOut; j++)
        {
            int temp;
            cin >> temp;
            g[nod].push_back(temp);
        }
    }
    
    for(int i = 1; i <= n; i++)
    {
        if(d[i] == 0){
            dfs(i);
        }
    }

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

    return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int t;

void dfs(int pos, vector<int>& d, vector<int>& f, vector<vector<int>>& a){
	d[pos] = t;
	rep(i,a.size()){
		if(a[pos][i] == 1 and d[i] == -1){
			t++;
			d[i] = t;
			dfs(i, d, f, a);
		}
	}
	t++;
	f[pos] = t;
}

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

	vector<vector<int>> a(n, vector<int>(n,0));
	rep(i,n){
		int from;
		int m;
		cin >> from >> m;
		from--;
		rep(j,m){
			int to;
			cin >> to;
			to--;
			a[from][to] = 1;
		}
	}

	vector<int> d(n,-1), f(n);
	t = 1;
	rep(i,n){
		if(d[i] == -1) {
			dfs(i, d, f, a);
			t++;
		}
	}

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

C++: #include <iostream>
#include <vector>
#include <string>

using namespace std;

int n;
vector<vector<int>> g; 
int time = 0;
vector<int> d, f;
 
void dfs(int node){
    time++;

    if(d[node] == 0){
        d[node] = time;
    }

    for(auto next : g[node]){
        if(d[next] == 0){
            dfs(next);
        }
    }
    
    time++;
    if(f[node] == 0){
        f[node] = time;
    }
    return;
}
    
int main(){
    
    cin >> n;

    d.assign(n + 1, 0);
    f.assign(n + 1, 0);

    g.assign(n + 1, vector<int>());

    for(int i = 0; i < n; i++)
    {
        int nod, numOut;
        cin  >> nod >> numOut;
        for(int j = 0; j < numOut; j++)
        {
            int temp;
            cin >> temp;
            g[nod].push_back(temp);
        }
    }
    
    dfs(1);

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

    return 0;
}