Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

C++: #include "bits/stdc++.h"
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 color[N],d[N],f[N],tt;
int nt[N];

//u?????£??\??????v?????????????????????
int next(int u){
	for (int v = nt[u]; v < n; ++v) {
		nt[u]=v+1;
		if(M[u][v])return v;
	}
	return -1;
}

//?????????????????¨????????±???????????¢?´¢
void dfs_visit(int r){
	for (int i = 0; i < n; ++i) {nt[i]=0;}
	stack<int> S;
	S.push(r);
	color[r]=GRAY;
	d[r]=++tt;
	while(!S.empty()){
		int u=S.top();
		int v=next(u);
		if(v!=-1){
			if(color[v]==WHITE){
				color[v]=GRAY;
				d[v]=++tt;
				S.push(v);
			}
		}else{
			S.pop();
			color[u]=BLACK;
			f[u]=++tt;
		}
	}
}

void dfs(){
	//?????????
	for (int i = 0; i < n; ++i) {
		color[i]=WHITE;
		nt[i]=0;
	}
	tt=0;
	//????¨???????u????§??????¨????????±???????????¢?´¢
	for (int u = 0; u < n; ++u) {
		if(color[u]==WHITE)dfs_visit(u);
	}
	for (int i = 0; i < n; ++i) {
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
	}
}


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;
		}
	}
	dfs();
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define N 100
using namespace std;
int M[N][N],n;
int color[N],d[N],f[N],tt;
void dfs_visit(int u)
{
  int v;
  color [u] = GRAY ;
  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++)
    {
      printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}
int main ()
{
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i = 0;i<n;i++)
   {
     for(j = 0;j<n;j++)
      M[i][j] = 0;
   }
  for(i = 0;i<n;i++)
  {
    scanf("%d %d",&u,&k);
    u--;
    for(i = 0;j<k;j++)
      {
        scanf("%d",&v);
        v--;
        M[u][v] =1;
      }
  }
  dfs();
  return  0 ;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int dfs(const int cur, const int par, int time, const vector<vi> &g, vi &d, vi &f) {
  if (d[cur] != 0)
    return time;
  d[cur] = time;
  time++;
  for (const auto u : g[cur]) {
    if (u == par)
      continue;
    time = dfs(u, cur, time, g, d, f);
  }
  f[cur] = time;
  time++;
  return time;
}

int main() {
  int n;
  cin >> n;
  vector<vi> g(n);
  REP(i, n) {
    int id, k;
    cin >> id >> k;
    id--;
    REP(j, k) {
      int u;
      cin >> u;
      u--;
      g[id].push_back(u);
    }
  }

  vi d(n, 0), f(n, 0);
  int time = 1;
  REP(i, n) { time = dfs(i, -1, time, g, d, f); }
  REP(i, n) { cout << i + 1 << " " << d[i] << " " << f[i] << endl; }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll C=0;
ll T[107],T1[107],T2[107];
vector<vector<ll>> V(107);

void dfs(int X){
    T[X]=1;
    C++;
    T1[X]=C;
    rep(i,V[X].size()){
        if(T[V[X][i]]==0){
            dfs(V[X][i]);
        }
    }
    C++;
    T2[X]=C;
}
 
int main(){
    ll N,A,B,C;
    cin >> N;
    rep(i,N){
        cin >> A >> B;
        rep(j,B){
            cin >> C;
            V[A].push_back(C);
        }
    }
    rep(i,N){
        if(T[i+1]==0){
            dfs(i+1);
        }
    }
    rep(i,N){
        cout << i+1 <<" "<< T1[i+1] << " " << T2[i+1] << endl;
    }
}