Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nVerts := scanInt(sc)
	graph := make([][]int, nVerts+1)

	for i := 0; i < nVerts; i++ {
		u := scanInt(sc)
		nDegrees := scanInt(sc)

		graph[u] = make([]int, nDegrees)
		for d := 0; d < nDegrees; d++ {
			graph[u][d] = scanInt(sc)
		}
	}

	starts := make([]int, nVerts+1)
	ends := make([]int, nVerts+1)
	time := 1

	var dfs func(u int)
	dfs = func(u int) {
		if starts[u] > 0 {
			return
		}

		starts[u] = time
		time += 1

		for _, v := range graph[u] {
			dfs(v)
		}

		ends[u] = time
		time += 1
	}

	for i := 1; i <= nVerts; i++ {
		dfs(i)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= nVerts; i++ {
		fmt.Fprintf(w, "%d %d %d\n", i, starts[i], ends[i])
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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 M[N][N], color[N], d[N], f[N], nt[N];
int tt,n;

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


void dfs() {
	for(int i = 0; i < n; i++){
		color[i] = WHITE; nt[i] = 0;
	}
	tt = 0; 
	
	for(int j = 0; j < n; j++) {
		if(color[j] == WHITE) {
			dfs_visit(j);
		}
	}
	
	for(int i =0; i < n; i++ ) {
    	cout << i+1 << " " << d[i] << " " << f[i] << 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;
      }	
	}
	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;

int n;
vector<int> g[110];
int in[110], out[110];

void dfs(int v, int& t) {
    in[v] = ++t;
    for (int nv : g[v]) if (!in[nv]) {
        dfs(nv, t);
    }
    out[v] = ++t;
}

int main() {
    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;
            g[u - 1].push_back(v - 1);
        }
    }
    int t = 0;
    for (int i = 0; i < n; ++i) if (!in[i]) {
        dfs(i, t);
    }
    for (int i = 0; i < n; ++i) {
        cout << i + 1 << " " << in[i] << " " << out[i] << endl;
    }
}

C++: #include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int n, i, j, u, v, k;
bool is_connected[150][150];

// 最初に発見した時刻
int d[150];
// 隣接リストを調べ終えた時刻
int f[150];

void init() {
    rep(i, n + 1) rep(j, n + 1) is_connected[i][j] = false;
    rep(i, n + 1) {
        d[i] = 0;
        f[i] = 0;
    }
    d[1] = 1;
}

// must handle infinite loop
int walkDepthFirst(int src_id, int time) {
    d[src_id] = time;

    int dst_id;
    rep(dst_id, n + 1) {
        if (is_connected[src_id][dst_id]) {
            // 未訪問
            if (d[dst_id] == 0) {
                time = walkDepthFirst(dst_id, time + 1);
            }
        }
    }

    time++;
    f[src_id] = time;
    return time;
}

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

    rep(i, n) {
        cin >> u >> k;
        rep(j, k) {
            cin >> v;
            is_connected[u][v] = true;
        }
    }

    int time = 1;
    int node = 1;
    // rep(i, n) {
    //     int cur_node = i + 1;
    //     if (d[cur_node] == 0 && f[cur_node] == 0) {
    //         time = walkDepthFirst(cur_node, time);
    //         time++;
    //     }
    // }

    time = walkDepthFirst(node, time);

    rep(i, n) {
        int cur_node = i + 1;
        if (d[cur_node] == 0) {
            time = walkDepthFirst(cur_node, time + 1);
        }
    }

    rep(i, n) {
        cout << i + 1 << " " << d[i + 1] << " " << f[i + 1] << endl;
    }

    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack<int> st;
int  v[102][101], n;
int  tim[102][2];
int ct = 1;
int go[102];
inline void search(int t) {
	if(!tim[t][0]) tim[t][0] = ct++;
	go[t] = 1;
	int tf = 0;
	for (int a = 1; a <= n; a++) {
		if (v[t][a]) {
			st.push(a);
			for (int i = 1; i <= n; i++) {
				v[i][a] = 0;
			}
			search(st.top());
			tf = 1;
		}
	}
		
	if(!tf) {
		st.pop();
		tim[t][1] = ct++;
		if(!st.empty()) search(st.top());
	}
}
int main() {

	st.push(1);
	int u, k, s;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			v[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			v[u][s] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		v[i][1] = 0;
	}
	search(1);
	for (int i = 2; i <= n; i++) {
		if (!go[i]) {
			st.push(i);
			for (int j = 1; j <= n; j++) {
				v[j][i] = 0;
			}
			search(i);
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << i << " " << tim[i][0] << " " << tim[i][1] << endl;
	}
	return 0;
}

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

vector<int> graph[100];
int start[100],endt[100];
int cnt;

void dfs(int num){
	start[num] = ++cnt;
	for(int i = 0;i < graph[num].size();i++){
		if(!endt[graph[num][i]]) dfs(graph[num][i]);
	}
	endt[num] = ++cnt;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int now,m;
		cin >> now >> m;
		for(int j = 0;j < m;j++){
			int t;
			cin >> t;
			graph[now - 1].push_back(t - 1);
		}
	}
	dfs(0);
	for(int i = 0;i < n;i++){
		cout << i + 1 << " " << start[i] << " " << endt[i] << endl;
	}
	return 0;
}

C++: //深度优先搜索 ,递归实现 
#include <iostream>

using namespace std;

const int N = 100;

const int NIL = -1;

int n;
bool graph[N+1][N+1] = {false}; //关系矩阵图 
char *color;//标记点的状态 B代表访问结束，W代表未访问，G代表正在访问 
int *d; //首次发现该点的时间 
int *f;  //结束访问该点的时间 

int mtime = 0; //当前的时间 


//递归的深度优先搜索 
void dfs(int u) {
	color[u] = 'G';
	d[u] = ++mtime;
	for (int j = 1;j<=n;j++) {
		if (graph[u][j] && color[j] == 'W') {
			dfs(j);
		}
	}
	color[u] = 'B';
	f[u] = ++mtime;
} 

int main() {
	cin >> n;
	color = new char[n+1]; 
	d = new int[n+1];
	f = new int[n+1];
	
	//初始化 
	for (int i = 1;i<=n;i++) {
		color[i] = 'W';
		d[i] = 0;
		f[i] = 0;
	}
	
	for (int i=0;i<n;i++) {
		int x,k;
		cin >> x >> k;
		for (int j = 0;j<k;j++) {
			int y;
			cin >> y;
			graph[x][y] = true; 
		}
	}
	
	for (int i = 1;i<=n;i++) {
		if (color[i] == 'W') {
			dfs(i);
		}
	}
	
	for (int i = 1;i<=n;i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	
	delete[] color;
	delete[] d;
	delete[] f;
}