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 <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

const int MAX = 110;
vector<int> G[MAX];
int dtime[MAX];
int ftime[MAX];
int n;
int tim;

void dfs(int p) {
    if (ftime[p] == -1) dtime[p] = ++tim;
    else return;
    for (int i = 0; i < G[p].size(); i++) {
        dfs(G[p][i]);
    }
    if (ftime[p] == -1) ftime[p] = ++tim;
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {G[i].clear(); dtime[i]=-1; ftime[i]=-1;}
    tim = 0;
    for (int i = 1; i <= n; i++) {
        int p, k;
        scanf("%d %d", &p, &k);
        while (k--) {
            int ne = 0;
            scanf("%d", &ne);
            G[p].push_back(ne);
        }
        sort(G[p].begin(), G[p].end());
    }
    for (int i = 1; i <= n; i++) {
        dfs(i);
    }
    for (int i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, dtime[i], ftime[i]);
    }
    return 0;
}

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

int n;
int t; //mytime?????????????????§???????´?
int mytime1[110],mytime2[110]; //?????§??????
int mat[110][110];
int c[110];

void dfs(int cur){
	t+=1;
	mytime1[cur]+=t;
	c[cur]=1;
	for(int dst=0; dst<n; ++dst){
		if(mat[dst][cur]==1&&c[dst]==0){
			dfs(dst);
		}
	}
	t += 1; 
	mytime2[cur]=t;
}


int main()
{
	vector<int> v[110];
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int tmp;
			cin>>tmp;
			v[u].push_back(tmp);
		}
	}
	for(int i=0;i<100;i++){
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			mat[i][j]=0;
		}
	}
	for(int i=1;i<n+1;i++){
		for(int j=0;j<v[i].size();j++){
			mat[i-1][v[i][j]-1]=1; //
		}
	}
	for(int i=0;i<n;i++){
    if(c[i]!=1){
      dfs(i);
    }
  }
  for(int i=0;i<n;i++)
    {
      cout<<(i+1)<<' '<<mytime1[i]<<' '<<mytime2[i]<<endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 105
#define BLACK 0
#define GRAY 1
#define WHITE 2

int n;
int G[MAX][MAX];
int d[MAX], f[MAX], color[MAX];
int t;

void init();
void dfs();
void dfs_s(int s);

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

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

    dfs();

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

void init(){
    t = 1;
    for(int i = 0; i < n; i++){
        d[i] = f[i] = 0;
        color[i] = WHITE;
        for(int j = 0; j < n; j++){
            G[i][j] = 0;
        }
    }
}

void dfs(){
    for(int i = 0; i < n; i++){
        if(color[i] == WHITE){
            dfs_s(i);
            t++;
        }
    }
}

void dfs_s(int s){
    stack<int> S;
    S.push(s); color[s] = GRAY; d[s] = t;
    int now;

    while(!S.empty()){
        now = S.top();
        t++;
        bool fl = true;

        for(int i = 0; i < n; i++){
            if(G[now][i] == 1 && color[i] == WHITE){
                S.push(i); color[i] = GRAY; d[i] = t;
                now = i; fl = false; break;
            }
        }

        if(fl){
            int top = S.top(); S.pop();
            color[top] = BLACK; f[top] = t;
            now = top;
        }
    }
}