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 "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

vector<int> D,F;

int dfs(int t,int p,int c,ConnectNodeInfo& connect){
	D[c]=t;
	for(auto& x:connect[c]){
		if(x.first!=p && D[x.first]==0){
			t = dfs(t+1,c,x.first,connect);
		}
	}
	t++;
	F[c]=t;
	return t;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	ConnectNodeInfo connect(N);
	vector<int> V(N);
	REP(i,N){
		int x=in()-1,k=in();
		REP(j,k){
			int y=in()-1;
			connect.AddDirectionalConnection(x,y,1);
		}
		V[i]=x+1;
	}
	D.resize(N,0);
	F.resize(N,0);
	int T=1;
	REP(i,N){
		if(D[i]==0) T = dfs(T,-1,i,connect)+1;
	}

	REP(i,N){
		out(V[i],D[i],F[i]);
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int N;
int tt = 0;
vector< vector<int> > G;
vector<int> H, d, f;
int itrNum[100001];
stack<int> S;

void dfs(int u){
    S.push(u);
    H[u] = 0;

    while(!S.empty()){
        u = S.top();  // ?¨????????????????
        if(d[u] == 0) d[u] = ++tt;
        auto itr_v = next(G[u].begin(), itrNum[u]);
        itrNum[u]++;
        if(itr_v != G[u].end()){
            int v = *itr_v;
            if(H[v] == -1){
                H[v] = 0;
                S.push(v);
            }
        }else{
            S.pop();
            H[u] = 1;
            f[u] = ++tt;
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    G = vector<vector<int> >(N);
    H = vector<int>(N, -1);
    d = vector<int>(N, 0);
    f = vector<int>(N, 0);
    memset(itrNum, 0, sizeof(itrNum));
    REP(i, N){
        int u,k;
        cin >> u >> k;
        u--;
        REP(j ,k){
            int v;
            cin >> v;
            v--;
            G[u].pb(v);
        }
    }

    REP(i, N) if(H[i] == -1) dfs(0);
    REP(i, N){
        cout << i+1 << " " << d[i] << " " << f[i] << "\n";
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int a[101][101],f[101],e[101],t=1;
int color[101];
int n;

void dfs(int u){
    f[u]=t++;
    color[u]=1;
    rep(v,n){
        if(color[v]==0 && a[u][v]) dfs(v);
    }
    e[u]=t++;

}

int main() {
    cin>>n;
    rep(i,n){
        int u,cur;
        cin>>u>>cur;
        rep(j,cur){
            int v;
            cin>>v;
            a[u-1][v-1]=1;
        }
    }
    rep(i,n){
        if(!color[i]) dfs(i);
    }
    rep(i,n) cout<<i+1<<" "<<f[i]<<" "<<e[i]<<endl;
}