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 <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------
int N, turn;
int d[111], f[111];
vector<vector<int>> G;

void dfs(int from) {
   d[from] = ++turn;
   for (int to : G[from]) {
      if (!d[to]) dfs(to);
   }
   f[from] = ++turn;
}

int main() {
   // 入力
   cin >> N;
   G = vector<vector<int>>(N);
   rep (i, N) {
      int u, k;
      cin >> u >> k;
      u--;
      rep (j, k) {
         int a;
         cin >> a;
         a--;
         G[u].push_back(a);
      }
   }

   rep (i, N) {
      if (!d[i]) dfs(i);
   }

   rep (i, N) {
      printf("%d %d %d\n", i+1, d[i], f[i]);
   }

   return 0;
}

C++: #include <bits/stdc++.h>
#define pb push_back
using namespace std;

int num = 1;
bool visited[1000];
vector<int> v[1000], seq[1000];
void dfs(int k){
    seq[k].pb(num++);
    if(visited[k]) return;
    visited[k] = 1;
    for (auto t : v[k]){
        if(visited[t]) continue;
        dfs(t);
    }
    seq[k].pb(num++); return;

}
int main(){
    int n; cin >> n;
    memset(visited, 0, sizeof(visited));
    for (int i = 0; i < n; i++){
        int x, y, z; cin >> x >> y;
        for (int j = 0; j < y; j++){
            cin >> z; v[x].pb(z);
        }
    }
    for(int i = 1; i <= n; i++)
        sort(v[i].begin(), v[i].end());
    dfs(1);
    for (int i = 1; i <= n; i++){
        cout << i << ' ';
        for (auto k : seq[i])
        cout << k << ' ';
        cout << '\n';
    }
}

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

using namespace std;

struct Node {
    bool visit = false;
    vector<int> next;
    int position = 0;
    int start = 0;
    int end = 0;
};

int main() {
    int n, id, k, temp, time = 1;
    Node node[101];
    stack<int> st;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            cin >> temp;
            node[id].next.push_back(temp);
        }
    }

    while (1) {
        int s = -1;
        for (int i = 1; i <= n; i++) {
            if (node[i].start == 0) {
                s = i;
                break;
            }
        }
        if (s == -1) {
            break;
        }
        
        node[s].start = time++;
        st.push(s);
        while (!st.empty()) {
            temp = st.top();
            if (node[temp].position < node[temp].next.size() && node[node[temp].next[node[temp].position]].visit == false) {
                node[node[temp].next[node[temp].position]].start = time++;
                st.push(node[temp].next[node[temp].position++]);
            }
            else {
                node[temp].visit = true;
                node[temp].end = time++;
                st.pop();
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << node[i].start << " " << node[i].end << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

#define N 105

struct Node{
    string color;
    int d;
    int f;
};

struct Node node[N];
int tt;
int AdjMat[N][N];

void DFS(int u, int n){
    node[u].color = "gray";
    node[u].d = ++tt ;
    for (int v = 1; v <= n; v++){
        if ( AdjMat[u][v] == 0 ) continue;
        if ( node[v].color == "white") DFS(v, n);
    }
    node[u].color = "black";
    node[u].f = ++tt;
}

void DFS_init(int n){
    for (int i = 1; i <= n; i++){
        node[i].color = "white";
    }
    tt = 0;
    
    for (int i = 1; i <= n; i++){
        if (node[i].color == "white") DFS(i, n);
    }
    for (int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, node[i].d, node[i].f);
    }
}

int main(){
    
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; i++ ){
        for (int j = 1; j <= n; j++){
            AdjMat[i][j] = 0;
        }
    }
    
    for (int i = 1; i <= n; i++){
        int u, k, v;
        cin >> u >> k;
        if ( k == 0 ) continue;
        for (int j = 1; j <= k; j++){
            cin >> v;
            AdjMat[u][v] = 1;
        }
        
    }
    DFS_init(n);
    
    return 0;
}