Go: package main

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

func main() {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	nextInt := func() int { scn.Scan(); r, _ := strconv.Atoi(scn.Text()); return r }
	w := bufio.NewWriter(os.Stdout)

	n := nextInt()
	vecs := make([][]int, n)
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			vecs[u-1] = append(vecs[u-1], nextInt()-1)
		}
	}

	ds := make([]int, n)
	fs := make([]int, n)
	founds := make([]bool, n)
	t := 0
	for i := range founds {
		if !founds[i] {
			t = dfs(vecs, ds, fs, founds, i, t)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(w, i+1, ds[i], fs[i])
	}

	w.Flush()
}

func dfs(vecs [][]int, ds, fs []int, founds []bool, i, t int) (time int) {
	t++
	ds[i] = t
	founds[i] = true
	for _, v := range vecs[i] {
		if !founds[v] {
			t = dfs(vecs, ds, fs, founds, v, t)
		}
	}
	t++
	fs[i] = t

	return t
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stack>
#include<string>
#define NIL -1

using namespace std;

const int white=0;
const int gray=1;
const int black=2;
const int maxn=1110;
int G[maxn][maxn];
int color[maxn];
int ne[maxn],d[maxn],f[maxn];
int n,tt; 

int next(int u)
{
	for(int v=ne[u];v<n;v++){
		ne[u]=v+1;
		if(G[u][v])return v;
	}
	return NIL;
}

void dfs(int r)
{
	if(r>=n||color[r]!=white)return;
	stack<int> st;
	memset(ne,0,sizeof(ne));
	st.push(r);
	color[r]=gray;
	d[r]=++tt;
	while(!st.empty()){
		int u=st.top();
		int v=next(u);
		if(v!=NIL){
			if(color[v]==white){
				color[v]=gray;
				d[v]=++tt;
				st.push(v);
			}
		}else{
			color[u]=black;
			st.pop();
			f[u]=++tt;
		}
	}
	while(color[r+1]!=white)r++;
	dfs(r+1);
}

int main()
{
	memset(color,white,sizeof(white));
	memset(G,0,sizeof(G));
	memset(f,0,sizeof(f));
	memset(d,0,sizeof(d));
	int u,k,v;
	cin>>n;
	//邻接矩阵存图 
	for(int i=0;i<n;i++){
		cin>>u>>k;
		u--;
		for(int j=0;j<k;j++){
			cin>>v;
			v--;
			G[u][v]=1;
		}
	}
	tt=0;
	dfs(0);
	for(int i=0;i<n;i++){
		cout<<i+1<<' '<<d[i]<<' '<<f[i]<<endl;
	}
	return 0;
}

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

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int> > G;
int d[111],f[111],u[111];
void dfs(int v,int& p){
  if(u[v]) return;
  u[v]=1;
  sort(G[v].begin(),G[v].end());
  d[v]=++p;
  for(int u:G[v]) dfs(u,p);
  f[v]=++p;
}
signed main(){
  int n;
  cin>>n;
  G.resize(n,vector<int>());
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      c--;
      G[u].push_back(c);
    }
  }
  int p=0;
  dfs(0,p);
  for(int i=0;i<n;i++) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;;
  return 0;
}