Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

C++: #include <cstdio>
using namespace std;
int tim = 0;
bool vis[107];
int G[107][107], d[107], f[107];
void dfs(int cur) {
	vis[cur] = true;
	d[cur] = ++tim;
	for (int i = 0; G[cur][i]; i++) {
		if (!vis[G[cur][i]]) dfs(G[cur][i]);
	}
	f[cur] = ++tim;
}
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
    	int u, k;
    	scanf("%d%d", &u, &k);
    	for (int j = 0; j < k; j++) {
    		scanf("%d", &G[u][j]);
		}
	}
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) dfs(i);
	}
	for (int i = 1; i <= n; i++) {
		printf("%d %d %d\n", i, d[i], f[i]);
	}
    return 0;
}

C++: #include<stdio.h>
#define N 100
#define WHITE 0
#define GREY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], time;

void dfs_visit(int u)
{
	int v;
	color[u] = GREY;
	d[u] = ++time;
	for(v = 0; v < n; v++)
	{
		if(M[u][v] == 0)
			continue;
		if(color[v] == WHITE)
			dfs_visit(v);
	}
	color[u] = BLACK;
	f[u] = ++time;
}

void dfs()
{
	int u;
	for(u = 0; u < n; u++)
		color[u] = WHITE;
	time = 0;
	
	for(u = 0; u < n; u++)
	{
		if(color[u] == WHITE)
			dfs_visit(u);
	}
	for(u = 0; u < n; u++)
	{
		printf("%d %d %d\n", u + 1, d[u], f[u]);
	}
}

int main()
{
	scanf("%d", &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++)
	{
		scanf("%d%d", &u, &k);
		u--;
		for(int j = 0; j < k; j++)
		{
			scanf("%d", &v);
			v--;
			M[u][v] = 1;
		}
	}
	
	dfs();
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <cstring>
#define N 101

using namespace std;

int visited[N], nt[N], discovery[N], finish[N], tt, n;
vector<int> G[N];

int next(int u) {
    for (int v = nt[u]; v < G[u].size(); v++) {
        nt[u] = v + 1;
        return G[u][v];
    }
    return -1;
}

void dfs(int r) {
    memset(nt, 0, sizeof(nt));

    stack<int> S;
    S.push(r);

    visited[r] = 1;
    discovery[r] = ++tt;

    while (!S.empty()) {
        int u = S.top();
        int v = next(u);

        if (v != -1) {
            if (visited[v] == 0) {
                visited[v] = 1;
                discovery[v] = ++tt;
                S.push(v);
            }
        }
        else {
            S.pop();
            visited[u] = 1;
            finish[u] = ++tt;
        }
    }
}

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

    memset(visited, 0, sizeof(visited));
    tt = 0;

    for (int i = 0; i < n; i++) {
        if (visited[i] == 0) {
            dfs(i);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << discovery[i] << " " << finish[i] << endl;
    }

    return 0;
}

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

using namespace std;

#define MAX 110
int num;
int matrix[MAX][MAX];
int dst[MAX];
int counter = 0;
int D[MAX];
int F[MAX];

void input(){
    cin >> num;
    for(int i=0;i<MAX;i++){
        dst[i] = -1;
        for(int j=0;j<MAX;j++){
            matrix[i][j] = 0;
        }
    }
    for(int i=1;i<=num;i++){
        int v; cin >> v;
        int tmp; cin >>tmp;
        for(int j=0;j<tmp;j++){
            int vi; cin >> vi;
            matrix[v-1][vi-1] = 1;
        }
    }
}

void dfs(int cur){
    counter++;
    D[cur] = counter;
    for(int i=0; i< num;i++){
        if(matrix[cur][i] == 1 && D[i]== 0)
            dfs(i);
    }
    counter++;
    F[cur] = counter;
    return;
}

int main(){
    input();
    for(int i=0;i<MAX;i++){
        D[i] = 0;
        F[i] = 0;
    }
    dfs(0);
    for(int i=0;i<num;i++){
        cout << i+1 << " " << D[i] << " " << F[i] << endl;
    }
}

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