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++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int count = 1;
std::vector<vector<int> > G;
std::vector<int> flag;
std::vector<int> in;
std::vector<int> out;
int N;
int dfs(int u, int count) {
	flag[u] = 1;
	
	in[u] = count;
	for (int i = 0; i < N; ++i) {
		if (flag[i] == 0 && G[u][i] == 1) {
			count = dfs(i, count + 1);
		}
	}
	out[u] = count + 1;
	return count + 1;
}

int main(int argc, char const *argv[]) {
	
	cin >> N;

	for (int i = 0; i < N; ++i) {
		G.push_back(vector<int>());
		flag.push_back(0);
		in.push_back(0);
		out.push_back(0);
		for (int j = 0; j < N; ++j) {
			G[i].push_back(0);
		}
	}

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

	dfs(0, 1);

	for (int i = 0; i < N; ++i) {
		cout << i + 1 << " " << in[i] << " " << out[i] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int Stime = 0;
vector<int> edges[100];
bool visit[100];
int be[100]; //begin
int en[100]; //end


void dfs(int cur) //curを訪問
{
	//curの訪問時間を記録
	Stime++;
	visit[cur] = true;

	//cout << "visiting " << cur+1 << "  time:" << time << endl;
	be[cur] = Stime;

	for (int i = 0; i < edges[cur].size(); ++i)
	{
		if (!visit[edges[cur][i]])
		{
			dfs(edges[cur][i]);
		}
	}

	Stime++;

	//cout << "finished visiting " << cur+1 << "  time:" << time << endl;
	en[cur] = Stime;

}
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < 100; ++i)
	{
		visit[i] = false;
	}

	int u,k,v;
	for (int i = 0; i < n; ++i)
	{
		cin >> u >> k;

		for (int j = 0; j < k; ++j)
		{
			cin >> v;
			edges[i].push_back(v-1);
		}
	}

	int temp = 0;
	int flag = true; //未探索のノードがあるかどうか
	while(flag)
	{
		dfs(temp);
		flag = false;
		for (int i = 0; i < n; ++i)
		{
			if (!visit[i])
			{
				temp = i;
				flag = true;
				break;
			}
		}
	}

	for (int i = 0; i < n; ++i)
	{
		cout << i+1 << " " << be[i] << " " << en[i] << endl;
	}
	return 0;
}

C++: #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

#define white 0
#define gray 1

int M[110][110];
vector<int> color(110,white),d(110),f(110);
int t=0;
int n;

void dfs(int u){
  color[u]=gray;
  d[u]=++t;
  for(int v=0;v<n;v++){
    if(M[u][v] && color[v]==white) dfs(v);
  }
  f[u]=++t;
}

int main(){
  cin>>n;
  
  rep(i,n){
    rep(j,n) M[i][j]=0;
  }
  
  int x,y,z;
  rep(i,n){
    cin>>x>>y;
    x--;
    rep(j,y){
      cin>>z;
      z--;
      M[x][z]=1;
    }
  }

  rep(i,n){
    if(color[i]==white) dfs(i);
  }
  
  rep(i,n) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  
  return 0;
}