Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

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

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

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

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

int n;
int g[101][101];
char c[101];
int visit[101];
int finish[101];
int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v;
            cin >> v;
            g[u][v] = 1;
        }

    }

   stack<int> s;
    for (int l = 1; l <= n; ++l) {
        c[l] = 'w';

    }
    int time = 0;
    int start = 0;
    int v;
    while(true) {
        start++;
        if(start == n) break;
        if(c[start] == 'w') {
            time++;
            s.push(start);
            c[start] = 'g';
            visit[start] = 1;
            while (s.size() != 0) {
                time++;
                v = s.top();
                int next = -1;
                for (int i = 1; i <= n ; ++i) {
                    if(i == v) {
                        continue;
                    }
                    if(g[v][i] && c[i] == 'w') {
                        next = i;
                        break;
                    }
                }
                if(next == -1) {
                    c[v] = 'b';
                    finish[v] = time;
                    s.pop();
                } else {
                    c[next] = 'g';
                    visit[next] = time;
                    s.push(next);
                }
            }
        }
    }

    for (int m = 1; m <= n; ++m) {
        cout << m << " " << visit[m ] << " " << finish[m] << endl;

    }



    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

vector<int> g[101];
bool visited[101]{};
P ans[101];

int dfs(int s, int t) {
    visited[s] = true;
    ans[s].first = t;
    REP(i, g[s].size()) {
        if (visited[g[s][i]]) continue;
        t = dfs(g[s][i], t + 1);
    }
    t++;
    ans[s].second = t;
    return t;
}

int main() {
    int n;
    cin >> n;
    REP(i, n) {
        int u, m;
        cin >> u >> m;
        REP(j, m) {
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    for (int i = 1, T = 0; i <= n; i++) {
        if (visited[i]) continue;
        T = dfs(i, T+1);
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}

C++: // ALDS1_12_A: Depth First Search
#include <iostream>
#include <vector>
#include <algorithm>
bool debug = false;

std::vector<std::pair<int,int>> runtime_memo;
std::vector<int> vertex_stat;
std::vector<std::vector<int>> adjacency_list;
int runtime = 0;

void init() {
    int total; std::cin >> total;
    /* Resize containers */
    runtime_memo.resize(total);
    vertex_stat.resize(total);
    adjacency_list.resize(total);
    for (int i=0;i<adjacency_list.size(); i++) {
        adjacency_list.at(i).resize(total);
    }
    for (int i=0; i<adjacency_list.size(); i++) {
        for (int j=0; j<adjacency_list.at(i).size(); j++) {
            adjacency_list.at(i).at(j) = 0;
        }
    }

    /* Set adjacency_list */
    int vertex, outdegree;
    for (int i=0; i<adjacency_list.size(); i++) {
        std::cin >> vertex >> outdegree;
        for (int j=0; j<outdegree; j++) {
            int tmp; std::cin >> tmp;
            adjacency_list.at(vertex-1).at(tmp-1) = 1;
        }
    }
}

void DepthFirstSearch(int vertex) {
    int tmp_vertex = vertex -1;
    vertex_stat.at(tmp_vertex) = 1;
    runtime++;
    runtime_memo.at(tmp_vertex).first = runtime;
    for (int i=0; i<adjacency_list.at(tmp_vertex).size(); i++) {
        if (adjacency_list.at(tmp_vertex).at(i) == 1) {
            if (vertex_stat.at(i) == 0) {
                if (debug) std::cout << "DepthFirstSearch(" << i+1 << ")" << "\n";
                DepthFirstSearch(i+1);
            }
        }
    }
    vertex_stat.at(tmp_vertex) = 2;
    runtime++;
    runtime_memo.at(tmp_vertex).second = runtime;
}

int main() {
    /* Initialization */
    init();
    /* Depth first search */
    for (int i=0; i<vertex_stat.size(); i++) {
        int id = i+1;
        if (vertex_stat.at(i) == 0) {
            DepthFirstSearch(id);
        }
    }
    /* Output */
    for (int i=0; i<adjacency_list.size(); i++) {
        int id = i+1;
        std::cout << id << " ";
        std::cout << runtime_memo.at(i).first << " ";
        std::cout << runtime_memo.at(i).second << "\n";
    }
}

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

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

using namespace std;


int adjacencyList[MAX + 1][MAX + 1];
int color[MAX + 1];
int d[MAX + 1];
int f[MAX + 1];
int n;
int timer;



int minWhiteNode(int v)
{

	for (int i = 1; i <= n; i++) {
		if (color[i] == WHITE && adjacencyList[v][i] == 1) {
			return i;
		}
	}
	return 	MAX + 1;
}


void dfs(int o)
{
	stack<int> S;
	int cr;


	S.push(o);
	color[o] = GRAY;
	d[o] = ++timer;

	while (S.size() > 0) 
	{
		cr = minWhiteNode(S.top());
		timer++;

		if (cr != MAX + 1) {
			S.push(cr);
			color[cr] = GRAY;
			d[cr] = timer;
		}
		else {
			int poped = S.top();
			S.pop();
			color[poped] = BLACK;
			f[poped] = timer;
		}
	}
}

int main(void)
{

	int u;
	int k;
	int v;


	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> u >> k;

		for (int j = 0; j < k; j++) {
			cin >> v;
			adjacencyList[u][v] = 1;
		}

	}

	for (int i = 1; i <= n; i++) {
		if (color[i] == WHITE) {
			dfs(i);
		}
	}

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

	return 0;
}