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>

using namespace std;

std::vector<int> graph[100];
int d[100]={0},f[100]={0};
int t = 0;

void dfs(int v){
  t++;
  d[v] = t;
  for(const auto &next_v:graph[v]){
    if(d[next_v]==0){
      dfs(next_v);
    }
  }
  t++;
  f[v] = t;
}

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;++i){
    int u,k;
    cin >> u >> k;
    for(int j=0;j<k;++j){
      int v;
      cin >> v;
      graph[u-1].push_back(v-1);
    }
  }
  
  for(int i=0;i<n;++i){
    if(d[i]==0) dfs(i);
  }
  for(int i=0;i<n;++i){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#define LEN 101
using namespace std;
int TIME;
int d[LEN];
int f[LEN];
int num;
int graph[LEN][LEN] = {0};
void dfs(int x){
    TIME++;
    d[x] = TIME;
    for(int i=1;i<num+1;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+1;i++){
        if(d[i]==0)
            dfs(i);
    }
    for(int i=1;i<num+1;i++){
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    return 0;
}

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

using namespace std;

static const int N = 100;

static const int WHITE = 0;

static const int GRAY = 1;

static const int BLACK = 2;




//用递归的方式实现图深度优先搜索


/**
 * color 标记访问状态的数组，
 * M[N][N] 邻接矩阵 如果存在定点i到顶点j的边，则M[i][j]=trul
**/
int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs(int u) {
    int v;
    color[u] = GRAY;

    d[u] = ++tt;

    for (v = 0; v < n; v++) {
        if (M[u][v] == 0)
            continue;
        if (color[v] == WHITE) {
            dfs(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

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

    for (u = 0; u < n; u++) {
        cout << u + 1 << " " << d[u] << " " << f[u] << 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 i = 0; i < k; i++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    dfs();
    return 0;
}

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

int n,t;
int d[100],f[100];
bool graph[100][100];

void dfs(int v){
    t++;
    d[v]=t;

    for(int v2=0; v2<n; v2++){
        if(graph[v][v2]) dfs(v2);
    }

    t++;
    f[v]=t;
}

int main(void){
    cin >> n;
    t=0;

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            graph[i][j]=false;
        }
    }
    for(int i=0; i<n; i++){
        int v,k; cin >> v >> k;
        for(int j=0; j<k; j++){
            int w; cin >> w;
            graph[v-1][w-1]=true;
        }
    }

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


}

C++: #include<iostream>
#include<stack>
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, tt;
int M[N][N], color[N], d[N], f[N], nt[N]; 

int next(int u){
	for(int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if(M[u][v] == 1) 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 {
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


void dfs() {
	for(int i = 0; i < n; i++) {
	     color[i] = WHITE;
	}	
	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 n, k , u, v;
	tt = 0;
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}
	cin >> k >> u;
	u--;
	for(int i = 0; i < k; i++) {
	    cin >> v;
	    v--;
		M[u][v] = 1; 
	}
	dfs();
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int a[101][101];
int n;
int tt;
int color[101];
int nt[101];
int d[101],p[101];

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

void dfs_visit(int r){
	memset(nt,0,sizeof(nt));
	d[r]=++tt;
	color[r]=1;
	stack<int >s;
	s.push(r);
	while(!s.empty()){
		int u=s.top();
		int v=next(u);
		if(v!=-1){
			if(color[v]==0){
				d[v]=++tt;
				color[v]=1;
				s.push(v);
			}
		}
		else{
			s.pop();
			color[u]=2;
			p[u]=++tt;
		}
	}
}

void dfs(){
	int u;
	tt=0;
	for(u=0;u<n;u++)color[u]=0;
	for(u=0;u<n;u++){
		if(color[u]==0)dfs_visit(u);
	}
	for(u=0;u<n;u++)
	cout<<u+1<<" "<<d[u]<<" "<<p[u]<<endl;
}

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