Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

C++: #include<iostream>
#include<vector>
#include<stack>
using namespace std;
#define MAX 101
#define VISITED 0;
#define UNVISITED -1
#define NO_POSSIBLE_VERTICE -3


int d[MAX], f[MAX];
int timeStamp = 0;
vector<int> adj[MAX];
stack<int> S;

bool isAdjacentVerticeUnvisited(int currVertice, int i){
	if (f[adj[currVertice][i]] == UNVISITED) 
		return true;
	else
		return false;
}

int getNextPossibleVertice(int currVertice) {
	int i = 0;
		
	for (i = 0; i < adj[currVertice].size(); i++){
		if (isAdjacentVerticeUnvisited(currVertice, i)){
			return adj[currVertice][i];
		}
	}

	return NO_POSSIBLE_VERTICE;

}

void dfs() {

	while (!S.empty()) {
		int currVertice = S.top();

		int nextNode = getNextPossibleVertice(currVertice);

		// cout << "dfs " << currVertice << " nt:" << nextNode << "\n";

		if (nextNode == NO_POSSIBLE_VERTICE) {
			f[currVertice] = ++timeStamp;
			S.pop();
		} else {
			d[nextNode] = ++timeStamp;
			f[nextNode] = VISITED;
			S.push(nextNode);
		}
	}

}


int main() {
	int n, i, j, vertice, id, degree;
	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> id;
		cin >> degree;
		for (j = 0; j < degree; j++) {
			cin >> vertice;
			if (id != vertice){
				adj[id].push_back(vertice);
			}
		}
	}
	// init
	for (i = 1; i <= n; i++) {
		f[i] = UNVISITED;
	}

	for (i = 1; i <= n; i++) {
		if (f[i] == UNVISITED) {
			S.push(i);
			d[i] = ++timeStamp;
			f[i] = VISITED;
			dfs();
		}
	} 
	

	// for (i = 1; i <= n; i++) {
	// 	for (j = 0; j < adj[i].size(); j++)
	// 		cout << " " << adj[i][j];
	// 	cout << "\n" << i <<" size : " << adj[i].size() << "\n";
	// }

	for (i = 1; i <= n; i++) 
		cout << i << " " << d[i] << " " << f[i] <<"\n";

}

C++: //
//  main.cpp
//  619
//
//  Created by 8595198919 on 14/06/16.
//  Copyright (c) 2014年 8595198919. All rights reserved.
//

#define _2
#ifdef _1
#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;

int dist[105];
queue<int> que;
vector<int> G[105];
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        dist[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    que.push(1);
    dist[1]=0;
    while(!que.empty()){
        int now = que.front();
        que.pop();
        int d = dist[now];
        rep(i,G[now].size()){
            if(dist[G[now][i]]==-1){
                dist[G[now][i]]=d+1;
                que.push(G[now][i]);
            }
        }
    }
    for(int i = 1;i <= n;i++) {
        cout <<i <<" " << dist[i]<<endl;
    }
}
#endif

#ifdef _2

#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;


vector<int> G[105];
int d[105];
int f[105];
int tm = 1;
void dfs(int p){
    d[p]=tm;
    rep(i,G[p].size()){
        if(d[G[p][i]]==-1){
            tm++;
            dfs(G[p][i]);
        }
    }
    f[p] = ++tm;
    return;
}
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        d[i]=-1;
        f[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    dfs(1);
    for(int i = 1;i <= n;i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }
}

#endif

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

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<LL, LL>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<LL>;

//==============================================
int n, tt = 0;
vvi M;
vi D, F, searchStatus;

// ??±???????????¢?´¢
void antDfs(int u) {
	searchStatus[u] = 1;

	// ?????????(??????)??????????????????
	D[u] = ++tt;
	REP3(i, 1, n) {
		if (M[u][i] == 0) continue;

		if (searchStatus[i] == -1) {
			antDfs(i);
		}
	}
	// ?????????(??????)???????????????
	F[u] = ++tt;

	// ??¢?´¢??????
	searchStatus[u] = 1;
}

void print() {
	REP3(i, 1, n) {
		cout << i << " " << D[i] << " " << F[i] << "\n";
	}
}

void solve() {

	REP3(i, 1, n) {
		if (searchStatus[i] == -1) {
			//????¨???????i????§??????¨????????±???????????¢?´¢?????????
			antDfs(i);
		}
	}

	// ??????
	print();
}

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

	cin >> n;
	
	M.resize(n + 1, vi(n + 1));
	D.resize(n + 1);
	F.resize(n + 1);

	// ??¢?´¢??¶??????????????? (?????¢?´¢)
	searchStatus.resize(n + 1, -1);

	
	int u, k, v;
	REP3(i, 1, n) {
		cin >> u >> k;
		REP3(j, 1, k) {
			cin >> v;
			M[u][v] = 1;
		}
	}

	solve();
	return 0;
}

C++: #include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
vll d(100),f(100);
ll t=0;
void dfs(vvll g,vb &v,ll x){
  v[x]=true;
  d[x]=++t;
  
  rep(i,0,g[x].size()){
    if(!v[g[x][i]]){
      dfs(g,v,g[x][i]);
    }
  }
  f[x]=++t;
  
}
int main(){
  ll n;cin>>n;
  vvll g(n,vll(0));
  vb visited(n,false);
  rep(i,0,n){
    ll m,k;cin>>m>>k;
    m--;
    rep(j,0,k){
      ll x;cin>>x;
      g[m].push_back(--x);
    }
  }
  rep(i,0,n){
    if(!visited[i]){
      dfs(g,visited,i);
    }
  }
  
  rep(i,0,n){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  }
}