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<iostream>
#include<vector>
#include<stack>
#include<map>
using namespace std;

int main() {
    int n;
    cin>>n;
    vector<vector<int> > arr(n);
    vector<int> tmparr;
    int u, k;
    int tmp;
    for(int i=0;i<n;++i){
        cin>>u>>k;
        u--;
        tmparr.clear();
        for(int j=0;j<k;++j){
            cin>>tmp;
            tmp--;
            tmparr.push_back(tmp);
        }
        arr[u] = tmparr;
    }
    stack<int> stack;
    stack.push(0);
    map<int, int> used;
    map<int, int> owari;
    map<int, pair<int, int> > ans;
    int state;
    int time = 1;
    while(!stack.empty()){
        while(!stack.empty()){
            state = stack.top();
            if(used[state]>0){
                if(owari[state]==0){
                    ans[state].second = time;
                    owari[state]++;
                    time++;
                }
                stack.pop();
            }
            else {
                ans[state].first = time;
                time++;
            }
            used[state]++;
            for(int i=arr[state].size()-1;i>=0;--i){
                if(used[arr[state][i]]==0){
                    stack.push(arr[state][i]);
                }
            }
        }
        for(int i=0;i<n;++i){
            if(used[i]==0){
                stack.push(i);
                break;
            }
        }
    }
    for(int i=0;i<n;++i){
        cout<<i+1<<" "<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

C++: #include <cstdio>

typedef struct vertex_{
    int found;
    int d;
    int f;
}vertex;

int search(vertex *array, int (*A)[101], int id, int n, int time){
    if(array[id].found)return time;
    array[id].found=1;
    array[id].d=++time;
    for(int i=1;i<=n;i++){
        if(A[id][i])time=search(array,A,i,n,time);
    }
    array[id].f=++time;
    return time;
}

int searchAll(vertex *array, int (*A)[101], int n){
    int time = 0;
    for(int id=1;id<=n;id++){
        if(!array[id].found){
            time=search(array,A,id,n,time);
            printf("%d\n",time);
        }
    }
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    vertex array[n+1];
    for(i=1;i<=n;i++)array[i].found=0;
    int A[101][101];
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            A[i][j]=0;
        }
    }
    for(i=1;i<=n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            A[u][v]=1;
        }
    }
    int time = searchAll(array, A, n);
    for(i=1;i<=n;i++)printf("%d %d %d\n",i,array[i].d,array[i].f);
    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

struct edge {
    int to, cost;
};

int V;
vector<int> G[1000000];
int st[1000000];
int en[1000000];
int t;

void DFS(int n) {
    t++;
    st[n] = t;
    int s = G[n].size();
    for (int i = 0; i < s; i++) {
        if (st[G[n][i]] == intmax) {
            DFS(G[n][i]);
        }
    }
    t++;
    en[n] = t;
}

int main() {
    int N;
    cin >> N;
    V = N;
    fill(st, st + V + 10, intmax);
    fill(en, en + V + 10, intmax);
    t = 0;
    for (int i = 0; i < N; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int n;
            cin >> n;
            G[i].push_back(n - 1);
        }
    }
    for (int i = 0; i < N; i++) {
        if (st[i] == intmax) {
            DFS(i);
        }
    }
    for (int i = 0; i < N; i++) {
        cout << i + 1 << " " << st[i] << " " << en[i] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int d[111],f[111],G[111][111],t=1,n;
int dfs(int now){
  d[now]=t++;
  for(int i=1;i<=n;i++)
    if(G[now][i]&&d[i]==0)dfs(i);
  f[now]=t++;
}

int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    int v2,v1,k;
    scanf("%d%d",&v1,&k);
    for(int j=0;j<k;j++){
      scanf("%d",&v2);
      G[v1][v2]=1;
    }
  }
  for(int i=1;i<=n;i++)if(d[i]==0)dfs(i);
  for(int i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],f[i]);
  
  return 0;
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<array>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int long long ll;
static const int N=100;
static const int white=0;
static const int gray=1;
static const int black=2;

int n,d[N],f[N],tt;
int color[N],nt[N];
int mp[N][N];

int next(int u){
    
    for(int v=nt[u];v<n;v++){
        nt[u]=v+1;
        if(mp[u][v]!=0)return v;
    }
    return -1;
}


void dfs_visit(int r){
    
    rep(i,n)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){
            d[v]=++tt;
            color[v]=gray;
            s.push(v);
        }else{
            color[u]=black;
            f[u]=++tt;
            s.pop();
        }
    }
}



void dfs(){

    rep(i,n){color[i]=white;nt[i]=0;}
    tt=0;
    
    for(int i=0;i<n;i++){
        if(color[i]==white){
            dfs_visit(i);
        }
    }
    rep(i,n){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        rep(j,b){
            int c;
            cin>>c;
            mp[a-1][c-1]=1;
        }
    }
    
    dfs();
    
    return 0;
}