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 <iostream>
#include <vector>
#include <stack>

using namespace std;

class Node {
public:
	vector<int> rels;
	int id, len, pos, ts1, ts2;
	Node();
	int next();
};

Node::Node() {
	pos = ts1 = ts2 = 0;
}

int Node::next() {
	if (pos >= len) return -1;
	int next = rels[pos];
	pos++;
	return next;
}


void dfs(int idx, Node **graph, stack<int> *stack, int *time) {
	stack->push(idx);
	graph[idx]->ts1 = ++(*time);
	while (stack->size() > 0) {
		int u = stack->top();
		int v = graph[u]->next();
		if (v != -1) {
			if (graph[v]->ts1 == 0) {
				graph[v]->ts1 = ++(*time);
				stack->push(v);
			}
		}
		else {
			graph[u]->ts2 = ++(*time);
			stack->pop();
		}
	}
}

int main() {
	int n, val, time;
	Node *graph[100];
	stack<int> stack;

	cin >> n;
	
	for (int i = 0; i < n; i++) {
		graph[i] = new Node();
		cin >> graph[i]->id;
		cin >> graph[i]->len;
		for (int j = 0; j < graph[i]->len; j++) {
			cin >> val;
			graph[i]->rels.push_back(val-1);
		}
	}

	time = 0;
	for (int i = 0; i < n; i++) {
		if (graph[i]->ts1 == 0)
			dfs(i, graph, &stack, &time);
	}


	for (int i = 0; i < n; i++) {
		cout << graph[i]->id << " " << graph[i]->ts1 << " " << graph[i]->ts2 << endl;
	}

	for (int i = 0; i < n; i++)
		delete(graph[i]);


	return 0;	
}

C++: #include <bits/stdc++.h>
using namespace std;
#define N 101
int s[N], f[N], tt = 0, n;
int graph[N][N];

void dfs(int node){
    if(s[node] == 0){
        s[node] = ++tt;
    }else return;
    for(int i = 0; i < n; i++){
        if(graph[node][i]) dfs(i);
    }
    f[node] = ++tt;
}

int main(){
    int u, k, val;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++)graph[i][j] = 0;
    }
    for(int i = 0; i < n; i++){
        scanf("%d %d", &u, &k);
        u--;
        for(int j = 0; j < k; j++){
            scanf("%d", &val);
            val--;
            graph[u][val] = 1;
        }
    }
    
    for(int i = 0; i < n; i++)dfs(i);
    for(int i = 0; i < n; i++)printf("%d %d %d\n", i + 1, s[i], f[i]);
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
const int maxx = 110;
int n, m[maxx][maxx];
int u, num, v;
int d[maxx], f[maxx];
int flag[maxx];
int nowtime = 1;

void dfs(int u) {

	// ??\?????¶??´
	flag[u] = 1;
	d[u] = nowtime++;
	for (int i = 1; i <= n; i++) {
		if (flag[i] == 0 && m[u][i] == 1) {
			dfs(i);
		}
	}
	//????????¶??´
	f[u] = nowtime++;
}

int main()
{

	scanf("%d", &n);
	memset(m, 0, sizeof(m));
	memset(f, 0, sizeof(f));
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &u, &num);
		for (int j = 1; j <= num; j++) {
			scanf("%d", &v);
			m[u][v] = 1;
		}
	}
	
	dfs(1);
	for (int i = 1; i <= n; i++) {
		printf("%d %d %d\n", i, d[i], f[i]);
	}
	return 0;
}

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

int t = 0;

void dfs(vector<vector<int>> &adj_list, vector<vector<int>> &res, int u)
{
    res[u][0] = ++t;
    for (int i = 0; i < adj_list[u].size(); i++)
    {
        int v = adj_list[u][i];
        if (res[v][0] == 0)
        {
            dfs(adj_list, res, v);
        }
    }
    res[u][1] = ++t;
}

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

    vector<vector<int>> adj_list(n);
    for (int i = 0; i < n; i++)
    {
        int id, k;
        cin >> id >> k;
        for (int j = 0; j < k; j++)
        {
            int u;
            cin >> u;
            adj_list[id - 1].push_back(u - 1);
        }
    }

    vector<vector<int>> res(n, vector<int>(2, 0));
    for (int i = 0; i < n; i++)
    {
        if (res[i][0] == 0)
        {
            dfs(adj_list, res, i);
        }
    }

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

    return 0;
}

C++: #include<cstdio>
#include<stack>
using namespace std;
const char N_MAX = 105;
char n;
unsigned char time=0;
stack<int> sta;
bool matrix[N_MAX][N_MAX];
struct Node{
    //0:undiscovered 1:active 2:end
    char state;
    unsigned char stTime, endTime;
};
Node V[N_MAX];
void buildMatrix(){
	for(char i=0; i<n;i++){
		int degree, index;
		scanf("%u%u", &index, &degree);
		for(char j=0; j<degree; j++){
			int temp;
			scanf("%d", &temp);
			matrix[index-1][temp-1] = true;
		}
	}
}
char next(char num){
    for(char i=0;i<n;i++){
        if(matrix[num][i]&&V[i].state==0){
            return i;
        }
    }
    return -1;
}
void dfs() {
    for(char i = 0; i < n; i++) {
        if(V[i].state == 0) {
            sta.push(i);
            V[i].stTime = ++time;
            V[i].state = 1;
            while(!sta.empty()) {
                char active = sta.top();
                char nex = next(active);
                if(nex != -1) {
                    sta.push(nex);
                    V[nex].stTime = ++time;
                    V[nex].state = 1;
                } else {
                    sta.pop();
                    V[active].endTime = ++time;
                    V[active].state = 2;
                }
            }
        }
    }
}
int main(){
    scanf("%d", &n);
    buildMatrix();
    dfs();
    for(char i=0;i<n;i++){
        printf("%d %d %d\n", i+1, V[i].stTime, V[i].endTime);
    }
}