Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) doesAllAdjsVisited(vertices []vertex) bool {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return false
		}
	}
	return true
}

func (v *vertex) isFirstVisit() bool {
	return v.firstVisitAt == 0
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func (v *vertex) nextVertex(vertices []vertex) (vertexId, error) {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return vId, nil
		}
	}
	return vertexId(-1), fmt.Errorf("illegal")
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	timestamp = timestamp + 1
	currentVertex := &vertices[currentId-1]
	if currentVertex.isFirstVisit() {
		currentVertex.firstVisitAt = timestamp
	}
	for !currentVertex.doesAllAdjsVisited(vertices) {
		nextVertexId, _ := currentVertex.nextVertex(vertices)
		timestamp = dfs(nextVertexId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	dfs(vertexId(1), 0, vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

C++: #include <cstdio>
#include <stack>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 100
using namespace std;

int A[MAX][MAX] = {0};
int color[MAX] = {0};
int f[MAX] = {0};
int d[MAX] = {0};
int time = 0;
int n;
stack<int> S;

int next(int u)
{
	for(int i=0; i<n; i++)
	{
		if(A[u][i])
		{
			if(color[i] == WHITE)
				return i;
		}
	}
	return -1;
}

void dfs(int u)
{
	S.push(u);
	color[u] = GRAY;
	d[u] = ++time;
	while(!S.empty())
	{
		int v = S.top();
		int x = next(v);
		if(x!=-1 && x!= v)
		{
			color[x] = GRAY;
			S.push(x);
			d[x] = ++time;
		}
		else
		{
			S.pop();
			color[v] = BLACK;
			f[v] = ++time;
		}
	}
}

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

	for(int i=0; i<n; i++)
	{
		if(color[i] == WHITE)
			dfs(i);
	}
	for(int i=0; i<n; i++)
	{
		printf("%d %d %d\n",i+1,d[i],f[i]);
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <stack>

using namespace std;
static const int N=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[N][N];
int d[N], color[N],f[N],tt;

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

void dfs(){
    int u;
    tt=0;
    for (u=0;u<n;u++)color[u]=WHITE;

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

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;
    VV g(n);
    rep(i,n){
        ll u,k;
        cin>>u>>k;
        u--;
        rep(j,k){
            ll x;
            cin>>x;
            x--;
            g[u].pb(x);
        }
    }

    Vec d(n,-1);
    Vec f(n,-1);
    ll time = 0;
    auto dfs = [&](auto dfs,ll v)->void{
        Each(x,g[v]){
            if(d[x]==-1){
                time++;
                d[x] = time;
                dfs(dfs,x);
            }
        }
        if(f[v]==-1){
            time++;
            f[v] = time;
        }
    };
    rep(i,n){
        if(d[i]==-1){
            time++;
            d[i] = time;
        }
        dfs(dfs,i);
    }
    rep(i,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    return  0;
}