Go: package main

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

var sc = bufio.NewScanner(os.Stdin)
var depth [101]int
var finish [101]int
var d [101]int
var n, time int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func visit(graph [][]int, u int) {
	depth[u] = 1
	time++
	d[u] = time
	for i := 0; i < n; i++ {
		if graph[u][i] == 1 {
			if depth[i] == 0 {
				visit(graph, i)
			}
		}
	}
	depth[u] = 2
	time++
	finish[u] = time
}
func main() {
	sc.Split(bufio.ScanWords)

	n = nextInt()
	graph := make([][]int, n)
	for i := 0; i < n; i++ {
		graph[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		s := nextInt()
		t := nextInt()
		if t == 0 {
			continue
		}
		for i := 0; i < t; i++ {
			u := nextInt()
			graph[s-1][u-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		if depth[i] == 0 {
			visit(graph, i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, d[i], finish[i])
	}
}

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

C++: #include<stdio.h>
int T=1,m[101][101],d[101]={0},a[101],b[101],n;
void visit(int u){
  int v; 
  a[u]=T++;
  d[u]=1;
  for(v=0;v<n;v++){
    if(m[u][v]==1&&d[v]==0){ 
      visit(v);
    }
  }   
  b[u]=T++;  
}
#include<stdio.h>
int main(){
  int k,i,j,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      m[i][j]=0;
 for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
       m[u-1][v-1]=1;      
   }
 }
 visit(0);
 for(i=0;i<n;i++)
   printf("%d %d %d\n",i+1,a[i],b[i]);
 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;
inline void search(int t) {
	if(!tim[t][0]) tim[t][0] = ct++;
	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;
		}
	}
	search(1);
	for (int i = 1; i <= n; i++) {
		cout << i << " " << tim[i][0] << " " << tim[i][1] << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

const int N = 100;
int A[N][N] = {{0}};
int n;
int t = 0;
int d[N] = {0};
int f[N] = {0};

void dfs(int id) {
    // cerr << "begin: " <<  id << " " << t << endl;
    if (d[id] != 0) {
        return;
    }
    ++t;
    d[id] = t;

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

    // cerr << "end: " <<  id << " " << t << endl;
    if (f[id] == 0) {
        ++t;
        f[id] = t;
    }
}

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

        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int x;
            cin >> x;
            A[u-1][x-1] = 1;
        }
    }

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


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

    return 0;
}

C++: #include <utility>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int c;
int a[100][100];
int times = 0;
vector<pair<int,int> > v;

vector<int> search(int node)
{
    vector<int> r;
    for(int i = 0;i<c;i++)
    {
        if(a[node][i] == 1)
            r.push_back(i);
    }
    return r;
}

int deep(int node)
{
    if(v[node].first == 0)
    {
        v[node].first = ++times;
        vector<int> r = search(node);
        for(int i = 0;i<r.size();i++)
        {
            deep(r[i]);
            
        }
        v[node].second = ++times;
    }
    else
        return -1;

    return 1;
}

int main() {

    cin >> c;
    for(int i= 0;i<c;i++)
        for(int j = 0;j<c;j++)
            a[i][j] = 0;
    v = vector<pair<int,int> >(c,{0,0});
    for(int i = 0; i<c;i++)
    {
        int rem[2];
        cin >> rem[0] >> rem[1];
        for(int j = 0;j<rem[1];j++)
        {
            int rem11;
            cin >> rem11;
            a[i][rem11-1] = 1;
        }
    }//cin fin
    for(int i = 0;i<c;i++)
    {
        if(v[i].first == 0)
            deep(i);
    }
    
    for(int i = 0; i<c;i++)
    {
        cout << i+1 << " " << v[i].first << " " << v[i].second << endl;
    }
    
    return 0;
}

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

static const int LEN = 110;      // 頂点数のMAX値+α
static const int UNVISITED = 0;  // 頂点の訪問状態:未訪問
static const int VISITED = 1;    // 頂点の訪問状態:訪問済み

// 頂点uに隣接する頂点vを番号順に取得
int next(int u, vector<int>& M_u, int& nt_u) {
    if (nt_u < M_u.size()) {
        return M_u[nt_u++];
    }
    return -1;
}

// スタックを用いた深さ優先探索
void dfs_visit(int r, int n, vector<vector<int>>& M, vector<int>& status,
               vector<int>& d, vector<int>& f, int& tt) {
    vector<int> nt(LEN);  // nt:隣接する頂点のうち,確認済みのものを保持

    for (int i = 0; i < n; ++i) {
        nt[i] = 0;
    }

    stack<int> S;  // 訪問途中の頂点を退避しておくスタック
    status[r] = VISITED;
    S.push(r);
    d[r] = ++tt;

    while (!S.empty()) {
        // スタックtopの頂点uを訪問し,
        // uに隣接している頂点で次に探索する頂点をvとして受け取る
        int u = S.top();
        int v = next(u, M[u], nt[u]);

        if (v == -1) {
            S.pop();
            f[u] = ++tt;
            continue;
        }

        if (status[v] == UNVISITED) {
            status[v] = VISITED;
            S.push(v);
            d[v] = ++tt;
        }
    }
}

void dfs(int n, vector<vector<int>>& M) {
    vector<int> status(LEN);  // status:頂点の訪問状態
    vector<int> d(LEN);       // d:頂点の発見時刻
    vector<int> f(LEN);       // f:頂点の完了時刻

    // 初期化 (頂点uの訪問状態を「未訪問」に,また時刻を0に)
    for (int i = 0; i < n; ++i) {
        status[i] = UNVISITED;
    }
    int tt = 0;  // tt:経過時刻

    // 未訪問の頂点rを始点として深さ優先探索開始
    for (int r = 0; r < n; ++r) {
        if (status[r] == UNVISITED) dfs_visit(r, n, M, status, d, f, tt);
    }

    // 結果を出力
    for (int i = 0; i < n; ++i) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int n, u, k, v;  // n:頂点数, u:頂点番号, k:出次数,
                     // v:隣接する頂点番号（入力受け取り用）
    vector<vector<int>> M(LEN,
                          vector<int>());  //  M:頂点同士の隣接を表す隣接リスト

    // 隣接リストを作成
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        --u;
        for (int j = 0; j < k; ++j) {
            cin >> v;
            --v;
            M[u].push_back(v);
        }
    }

    dfs(n, M);

    return 0;
}