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<bits/stdc++.h>
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

typedef vector<int> vi;

/* global variables */

vi nbrs[MAX_N];
int ds[MAX_N], fs[MAX_N];

/* subroutines */

int dfs(int u, int t) {
  ds[u] = ++t;

  for (int i = 0; i < nbrs[u].size(); i++) {
    int &v = nbrs[u][i];
    if (! ds[v]) t = dfs(v, t);
  }

  return (fs[u] = ++t);
}

/* main */

int main() {
  int n;
  cin >> n;

  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--;
      nbrs[u].push_back(v);
    }
  }

  int t = 0;
  for (int i = 0; i < n; i++)
    if (! ds[i]) t = dfs(i, t);

  for (int i = 0; i < n; i++)
    printf("%d %d %d\n", i + 1, ds[i], fs[i]);

  return 0;
}

C++: #include<iostream>
#include<cstdio>
#define N 101
using namespace std;

int g[N][N]; 
int d[N];
int f[N];
int n;
int times=0;
bool us[N];

//dfs
void dfs(int x){
  
  times++;
  d[x]=times;

  for(int i=1;i<=n;i++){
    if(g[x][i]==1 &&us[i]==false){
      us[i]=true;
      // cout <<"i "<<i<<endl;
      dfs(i);
    }
  } 
  f[x]=times=times+1;

}


int main(){
  
  int n2,data,u;

  //load n
  cin >>n;
  
  //initialize
  for(int i=0;i<N;i++){
    us[i]=false;
    for(int j=0;j<N;j++){
      g[i][j]=0;
    }
  }
  
  //load data
  for(int i=0;i<n;i++){
    scanf("%d%d",&u,&n2);
    for(int j=0;j<n2;j++){
      scanf("%d",&data);
      g[u][data]=1;
    }
  }
  
  //execute
  dfs(1);

  //print
  for(int i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  
  return 0;
}

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

struct ver{
    ll d;
    ll f;
};

ll t=0;
vector<vector<ll>> mat;
vector<ver> vers;

void find(ll pos) {
    if(vers[pos].d == 0){
        t++;
        vers[pos].d = t;
        for(ll i:mat[pos]) {
            find(i);
        }
        if(vers[pos].f == 0) {
            t++;
            vers[pos].f = t;
        }
    }
}

int main() {
    ll n;
    cin >> n;
    for(ll i=0;i<n;i++) {
        ll u,k;
        cin>>u>>k;
        vector<ll> aaa;
        for(ll j=0;j<k;j++) {
            ll tmp;
            cin>>tmp;
            aaa.push_back(tmp-1);
        }
        mat.push_back(aaa);
    }
    for(ll i=0;i<n;i++) {
        vers.push_back(ver{0,0});
    }
    for(ll i=0;i<n;i++) {
        if(vers[i].d == 0)find(i);
    }
    for(ll i=0;i<n;i++) {
        cout << i+1<<" "<<vers[i].d<<" "<<vers[i].f<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <stack>

using namespace std;
const int INF = 1001001001;

void step1(vector< vector<int> >& edges, vector<int>& d, vector<int>& f, vector<int>& color, int node, int& time)
{
    // stackを使用
    stack<int> S;
    S.push(node);
    d[node] = ++time;
    color[node] = 1;
    while(!S.empty())
    {
        node = S.top();
        if(color[node] != 2){
            bool flag = true;
            for(int e : edges[node])
            {
                if(color[e] == 0)
                {
                    S.push(e);
                    d[e] = ++time;
                    color[e] = 1;
                    flag = false;
                    break;
                }
            }
            if(flag) color[node] = 2;
        }
        else
        {
            f[node] = ++time;
            S.pop();
        }
    }
}

void step2(vector< vector<int> >& edges, vector<int>& d, vector<int>& f, vector<int>& color, int node, int& time)
{
    d[node] = ++time;
    color[node] = 1;
    for(int e : edges[node])
        {
            if(color[e] == 0) step2(edges, d, f, color, e, time);
        }
    
    f[node] = ++time;
}

void dfs(vector< vector<int> >& edges, vector<int>& d, vector<int>& f, vector<int>& color, int n)
{
    int time=0;
    for(int i=0;i<n;++i)
    {
        if(color[i] == 0) step2(edges, d, f, color, i, time);
    }
}

int main()
{
    int n, u, k, e;
    cin >> n;
    vector< vector<int> > edges(n);
    vector<int> d(n), f(n), color(n);
    for(int i=0;i<n;++i)
    {
        //d[i] = f[i] = INF;
    }
    for(int i=0;i<n;++i)
    {
        cin >> u >> k;
        --u;
        for(int j=0;j<k;++j)
        {
            cin >> e;
            --e;
            edges[u].push_back(e);
            //edges[e].push_back(u);
        }
    }

    dfs(edges, d, f, color, n);
    for(int i = 0;i < n; ++i)
    {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}