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)
	dfs(&g, &d, &f, 1, 1)

	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++: #define _CRT_SECURE_NO_WARNINGS
#include<cstdio>

bool table[102][102] = {};
int color[102] = {}; //0:?????¢?´¢???1:?¨??????????, 2:??¢?´¢??????
int n, counter = 0;
int t_visit[102] = {};
int t_finish[102] = {};

void DFS(int y) {
	
	for (int j = 0; j <= n - 1;j++) {

		//?¨????or??¢?´¢???????????£???????????????
		if ((table[y][j] == 1)&&(color[j] == 0)) {
			color[y] = 1; //?¨???????????????????
			if (t_visit[y] == 0) t_visit[y] = ++counter;
			DFS(j);
		}

	}

	color[y] = 2; //??¢?´¢???????????????
	if (t_visit[y] == 0) t_visit[y] = ++counter;
	if (t_finish[y] == 0) t_finish[y] = ++counter;
	
}

int main(void) {
	int u, k, s;

	scanf("%d", &n);

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


	for (int i = 0;i <= n - 1;i++) {
		if (color[i] == 0) {
			DFS(i);
		}
	}


	for (int i = 0; i <= n - 1;i++) {
		printf("%d %d %d\n", i + 1, t_visit[i], t_finish[i]);
	}

	return 0;
}

C++: #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, time1=0, M[N][N], color[N];
int nt[N], begin[N], end[N];

int next(int r)
{
	int i;
	for(i=nt[r]; i<n; i++)
	{
		nt[r]=i+1;
		if(M[r][i]==0)
			continue;
		if(color[i]==WHITE)
			return i;
	}
	return -1;
	
}

void dfs_visit(int r)
{
	int i, j;
	stack<int> S;
	S.push(r);
	color[r]=GRAY;
	begin[r]=++time1;
	
	while(!S.empty())
	{
		int u=S.top();
		int v=next(u);
		if(v!=-1)
		{
			begin[v]=++time1;
			color[v]=GRAY;
			S.push(v);
		}
		else
		{
			S.pop();
			color[u]=BLACK;
			end[u]=++time1;
		}

	}
}

void dfs()
{
	int i, j;
	for(i=0; i<n; i++)
	{
		color[i]=WHITE;
		nt[i]=0;
	}

	for(i=0; i<n; i++)
	{
		if(color[i]==WHITE)
		{
			dfs_visit(i);
		}
	}
	for(i=0; i<n; i++)
	{
		cout<<i+1<<" "<<begin[i]<<" "<<end[i]<<endl;
	}
}

int main()
{
	int i, j;
	int u, v, k;
	cin>>n;
	for(i=0; i<n; i++)
	{		
		for(j=0; j<n; j++)
		{
			M[i][j]=0;
		}
	}
	
	for(i=0; i<n; i++)
	{
		cin>>v>>k;
		v--;
		for(j=0; j<k; j++)
		{
			cin>>u;
			u--;
			M[v][u]=1;
		}
	}

	dfs();
	return 0;
}

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

using namespace std;

#define FIND 0
#define END 1

int  N;
bool Path[101][101] = {false};
int  TIME[101][2] = {0};
int time_tt;


void DFS(int i){
    if(!(TIME[i][FIND])) {
        time_tt++;
        TIME[i][FIND] = time_tt;
    }
    
    for (int p = 1; p <= N; p++) {
        if (Path[i][p]) DFS(p);
    }
    
    if(!(TIME[i][END])) {
        time_tt++;
        TIME[i][END] = time_tt;
    }
}

int main(){
    cin >> N;
    int bb;
    for (int i = 1; i <= N; i++) {
        int K;
        scanf("%d %d",&bb,&K);
        for (int k = 0; k < K; k++) {
            int p;
            scanf("%d",&p);
            
            Path[i][p] = true;
        }
    }
    
    time_tt = 0;
    
    DFS(1);
    
    for (int i = 1; i <= N; i++) {
        printf("%d %d %d\n",i,TIME[i][FIND],TIME[i][END]);
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vi g[110];
vi f, d;
int t = 1;

void dfs(int v, int p=-1){
    d[v] = t++;
    for(auto u : g[v]){
        if(u == p || d[u] != 0) continue;
        dfs(u, v);
    }
    f[v] = t++;
};

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    rep(i,n){
        int u,k; cin >> u >> k;
        rep(j,k){
            int v; cin >> v;
            g[u].push_back(v);
        }
    }

    f = vi(n+1), d = vi(n+1);
    REP(i,1,n+1){
        if(d[i] == 0) dfs(i);
    }
    REP(i,1,n+1){
        printf("%d %d %d\n", i, d[i], f[i]);
    }
    return 0;
}