Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int V;
Graph G;
vector<int> d;
vector<int> f;
vector<int> color;

#define WHITE 0
#define GRAY 1
#define BLACK 2

int now;

void dfs(const Graph &G, int v){
    color[v] = GRAY;
    d[v] = ++now;
    for(auto nv : G[v]){
        if(color[nv]==WHITE){
            dfs(G, nv);
        }
    }
    color[v] = BLACK;
    f[v] = ++now;
}

int main()
{
    now = 0;
    cin >> V;
    G.resize(V);
    d.assign(V, -1);
    f.assign(V, -1);
    color.assign(V, 0);
    rep(j, V)
    {
        int from;
        cin >> from;
        --from;
        int k;
        cin >> k;
        rep(i,k){
            int to;
            cin >> to;
            --to;
            G[from].push_back(to);
        }
    }
    for (int i = 0; i < V; i++){
        if(color[i] == WHITE)
            dfs(G, i);
    }

    for (int i = 0; i < V; i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

vector<UL> E[100];
UL ans[100][2]={};
UL tp=0;
bool F[100]={};

void DFS(UL p){
 F[p]=true;
 tp++; ans[p][0]=tp;
 for(UL e:E[p]){
  if(F[e]) continue;
  DFS(e);
 }
 tp++; ans[p][1]=tp;
}

int main() {
 UL N; scanf("%u",&N);
 rep(i,N){
  UL v; scanf("%u",&v); v--;
  UL c; scanf("%u",&c);
  rep(i,c){
   UL e; scanf("%u",&e); e--;
   E[v].push_back(e);
  }
 }
 rep(i,N) if(!F[i]) DFS(i);
 rep(i,N) printf("%u %u %u\n",i+1,ans[i][0],ans[i][1]);
 return 0;
}

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

#define int long long

const int N = 100 + 3;
vector<int> g[N];
int time_entry[N];
int time_exit[N];
bool visited[N];
int dfs_timer = 1;

void dfs(int s){
   	visited[s] = true;
    time_entry[s] = dfs_timer++;
   	for(auto it : g[s]){
	  if (!visited[it]) dfs(it);	  	
	}
	time_exit[s] = dfs_timer++;
}
	
int32_t main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) visited[i] = false;
  for(int i = 0; i < n; i++){
	  int m, deg;
	  cin >> m >> deg;
	  m--;
	  for (int i = 0; i < deg; i++){
		  int x;
		  cin >> x;
		  x--;
		  g[m].push_back(x);  
	  }  
   }
  for(int i = 0; i < n; i++){
	    if (!visited[i]) dfs(i);
	}
  for(int i = 0; i < n; i++){
	   int idx = i + 1;
	   cout << idx << " "<< time_entry[i] <<  " "<< time_exit[i] << endl;  
	}     	
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


void dfs(vvi g,int v, int &time,vb &seen,vi &first_time,vi &last_time) {
  first_time[v]=++time;
  seen[v]=true;
  for(auto next_v:g[v]) {
    if(seen[next_v]) continue;
    dfs(g,next_v,time,seen,first_time,last_time);
  }
  last_time[v]=++time;
}

int main() {
  int n;
  cin >> n;
  vvi G(n);
  REP(i,n) {
    int a;
    cin >> a;
    a--;
    int k;
    cin >> k;
    REP(j,k) {
      int b;
      cin >> b;
      b--;
      G[a].push_back(b);
    }
  }
  int time=0;
  vb seen(n,false);
  vi first_time(n,1);
  vi last_time(n,1);
  REP(i,n) {
    if(seen[i]) continue;
    dfs(G,i,time,seen,first_time,last_time);
  }
  REP(i,n) {
    cout << i+1 << " " << first_time[i] << " " << last_time[i] << endl;
  }
  return 0;
}

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

int cnt=0;

void DFS(int k, vector<vector<int> >& V, vector<pair<int,int> >& time) {
	time[k].first=cnt++;
	for(int i=1; i<=(int)V[k].size(); ++i) {
		if(time[V[k][i]].first==-1) {
			DFS(V[k][i],V,time);
		}
	}
	time[k].second=cnt++;
	return;
}

int main() {
	int i,j;
	int n;
	int u,k;
	vector<vector<int> > V;
	vector<pair<int,int> > time;
	scanf("%d",&n);
	V.resize(n+1);
	V[0].resize(n+1);
	time.resize(n+1);
	for(i=1; i<=n; ++i) {
		V[0][i]=i;
		scanf("%d%d",&u,&k);
		V[u].resize(k);
		time[u]={-1,-1};
		for(j=1; j<=k; ++j) {
			scanf("%d",&V[u][j]);
		}
	}
	DFS(0,V,time);
	for(i=1; i<=n; ++i) {
		printf("%d %d %d\n",i,time[i].first,time[i].second);
	}
	return 0;
}

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

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

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

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

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

  for(u = 0; u < n; ++u){
    if(color[u] == WHITE) dfs_visit(u);
  }
  for(u = 0; u < n; ++u){
    cout << u+1 << " " << d[u] << " " << f[u] << endl;
  }
}

int main(){
  int u, v, k;

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

  dfs();


  return 0;
}