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) doesAllAdjsVisited(vertices []vertex) bool {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return false
		}
	}
	return true
}

func (v *vertex) isFirstVisit() bool {
	return v.firstVisitAt == 0
}

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

func (v *vertex) nextVertex(vertices []vertex) (vertexId, error) {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return vId, nil
		}
	}
	return vertexId(-1), fmt.Errorf("illegal")
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	timestamp = timestamp + 1
	currentVertex := &vertices[currentId-1]
	if currentVertex.isFirstVisit() {
		currentVertex.firstVisitAt = timestamp
	}
	for !currentVertex.doesAllAdjsVisited(vertices) {
		nextVertexId, _ := currentVertex.nextVertex(vertices)
		timestamp = dfs(nextVertexId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

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

	dfs(vertexId(1), 0, 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<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;
int ms[100][100],n,tt=0;
int color[101],nt[101];
int d[100],f[100];
int next(int v){
    for(int i=nt[v];i<n;i++){
        nt[v]=i+1;
        if(ms[v][i]==1)return i;
    }
    return -1;
}

void visit_dfs(int v){
    stack<int> s;
    s.push(v);
    d[v]=++tt;
    color[v]=1;
    while(!s.empty()){
        int u=s.top();
        int uu=next(u);
        if(uu!=-1){
            if(color[uu]==0){
            s.push(uu);
            d[uu]=++tt;
            color[uu]=1;
            }
        }else{
            s.pop();
            f[u]=++tt;
            color[u]=2;
        }
    }
    
    
}
void dfs(){
    for(int i=0;i<n;i++){
        color[i]=0;
        nt[i]=0;
    }
    for(int i=0;i<n;i++){
        if(color[i]==0){
            visit_dfs(i);
        }
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

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

    
}

C++: #include <iostream>
#include <stack>
#define N 100
#define WHITE 0
#define GRAY  1
#define BLACK 2
#define NIL -1

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

// uの隣接点を番号順に取得する
// nt[N]には番号順での探索開始位置を保存する
// 隣接点がなければ-1を返す
int next(int u)
{
	for (int v = nt[u]; v < n; v++)
	{
		nt[u]++;
		if (M[u][v]) return v;
	}
	return NIL;
}

// rを開始地点として深さ優先探索を行う
void dfs_visit(int r)
{
	std::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 != NIL)
		{
			if (color[v] == WHITE)
			{
				S.push(v);
				color[v] = GRAY;
				d[v] = tt++;
			}
		}
		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 = 1;

	for (int i = 0; i < n; i++)
	{
		if (color[i] == WHITE) dfs_visit(i);
	}

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

int main()
{
	std::cin >> n;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			M[i][j] = 0;
		}
	}

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

	dfs();
}

C++: #include <iostream>
#include <stack>
using namespace std;
const int MAX_N = 100;

int A[MAX_N+1][MAX_N+1];
pair<int, int> TIMESTAMPS[MAX_N+1];
int N;

void solve() {
  int ts = 0;
  stack<int> S;

  for (int i = N; i > 0; i--) {
    if (TIMESTAMPS[i].first == 0) S.push(i);
  }

  while (!S.empty()) {
    int c = S.top();

    if (TIMESTAMPS[c].first == 0)
      TIMESTAMPS[c].first = ++ts;

    for (int i = N; i > 0; i--) {
      if (A[c][i] == 1 && TIMESTAMPS[i].second == 0)
        S.push(i);
    }

    if (S.top() == c) {
      if (TIMESTAMPS[c].second == 0)
        TIMESTAMPS[c].second = ++ts;
      S.pop();
    }
  }
}

int main() {
  cin >> N;

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      A[i][j] = 0;

    }
    TIMESTAMPS[i] = make_pair(0, 0);
  }

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

  solve();

  for (int i = 1; i <= N; i++) {
    cout << i << ' '
         << TIMESTAMPS[i].first << ' '
         << TIMESTAMPS[i].second << endl;
  }

  return 0;
}

C++: #include <iostream>
 
using namespace std;
 
    int TIME = 0;
    int d[101];
    int f[101];
    int num;
    int graph[101][101] = {0};
 
void dfs(int x){
    TIME++;
    d[x] = TIME;
 
    for(int i=1;i<=num;i++){
        if(graph[x][i] == 1 && d[i]==0){
            dfs(i);
        }
    }
    f[x] = ++TIME;
}
 
int main(){
    int hon;
    int eda;
    int ver;
 
    cin>>num;
    for(int i=0;i<num;i++){
        cin>>eda;
        cin>>hon;
        for(int j=0;j<hon;j++){
            cin>>ver;
            graph[eda][ver]++;
        }
    }
     
    for(int i=1;i<=num;i++){
        if(d[i]==0)
            dfs(i);
    }
 
    for(int i=1;i<=num;i++){
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }
 
    return 0;
}