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 <stdio.h>
#define MAX_N (105)

int n;
int G[MAX_N + 1][MAX_N + 1];
int d[MAX_N + 1];		// ????????????
int f[MAX_N + 1];		// ????????????
int time;
int dfs(int cur)
{
    d[cur] = time;
    for ( int i = 1; i <= n; i++ ) {
	if ( G[cur][i] && (d[i] == 0)) {
	    time++;
	    dfs(i);
	}
    }
    time++;
    f[cur] = time;
}

int main()
{
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);
	for ( int j = 0; j < k; j++ ) {
	    int v;
	    scanf("%d", &v);
	    G[u][v] = 1;
	}
    }

    time = 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 <stack>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int r){
    stack<int> S;

    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!S.empty()){
        int u = S.top();
        int v = -1;
        for (int j = 0; j < n; ++j){
            if(M[u][j] == 1 && color[j] == WHITE) {
                v = j;
                break;
            }
        }
        if (v != -1){
            S.push(v);
            color[v] = GRAY;
            d[v] = ++tt;
        } else {
            color[u] = BLACK;
            f[u] = ++tt;
            S.pop();
        }
    }
}

void dfs(){
    int u;
    // initialization
    for( u = 0; u < n; ++u) color[u] = WHITE;
    tt = 0;

    for( u = 0; u < n; ++u){
        if (color[u] == WHITE) dfs_visit(u);
    }

    for( u = 0; u < n; ++u){
        printf("%d %d %d\n", u+1, d[u], f[u]);
    }
}

int main()
{
    int u, v, k, i, j;
    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);
        --u;
        for (j = 0; j < k; ++j){
            scanf("%d", &v);
            --v;
            M[u][v] = 1;
        }
    }

    dfs();
    
    return 0;
}

C++: #ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

constexpr auto no_value = numeric_limits<uint64_t>::max();

struct GraphParser {
  GraphParser(vector<vector<int>>& edges_)
      : edges(edges_), start(edges.size(), 0), end(edges.size(), 0) {
    //
  }

  void run() {
    t = 0;
    recur(0);
  }

  vector<vector<int>>& edges;
  vector<int> start;
  vector<int> end;
  int t;

 private:
  void recur(int cur) {
    if (start[cur]) {
      return;
    }
    start[cur] = ++t;
    for (auto&& e : edges[cur]) {
      recur(e);
    }
    end[cur] = ++t;
  }
};

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

  GraphParser p(edges);
  p.run();
  for (int i = 0; i < n; ++i) {
    cout << (i + 1) << " " << p.start[i] << " " << p.end[i] << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

vector<int> d;
vector<int> f;
int t;
void dfs(vector<vector<int>>Graph, int v) {
  d[v] = t;
  t++;
  if(Graph[v].size() == 0) {
    return;
  }
  for(auto next_v: Graph[v]) {
    if(d[next_v] != -1) {
      continue;
    }
    //cout << next_v << ":" << t << endl;
    dfs(Graph, next_v);
    f[next_v] = t;
    t++;
  }
  f[v] = t;
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> Graph(n);
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    rep(j, k) {
      int a;
      cin >> a;
      Graph[i].push_back(a-1);
    }
  }
  d = f = vector<int>(n, -1);
  d[0] = 1;
  t = 1;
  dfs(Graph, 0);
  f[0] = t;
  rep(i, n) {
    if(d[i] == -1) {
      t++;
      dfs(Graph, i);
      //f[i] = t;
    }
  }
  rep(i, n) {
    cout << i + 1 << " ";
    cout << d[i] << " ";
    cout << f[i] << endl;
  }
}

C++: /* 深さ優先探索
 １．一番最初に訪問する頂点をスタックに入れる
 ２．スタックに頂点が積まれている限り...
 　- スタックのトップにある頂点uを訪問する
   - 現在訪問中の頂点uから次の頂点vへ移動する時に、vをスタックへ積む。
   　uに未訪問の隣接する頂点がなければuをスタックから削除する
*/

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

// uに隣接するvを番号順に取得
int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (M[u][v]) return v; // 隣接する頂点vを返す
	}
	return -1; // 隣接する頂点がないなら-1を返す
}

// スタックを用いて深さ優先探索
void dfs_visit(int r) {
	for (int i = 0; i < n; i++) nt[i] = 0;

	stack<int> S;
	S.push(r);
	color[r] = GRAY; // 現在訪問中の頂点
	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; // 経過時刻を表すタイムスタンプを0に設定
	}
	tt = 0;

	// 未訪問のuを始点として深さ優先探索
	for (int u = 0; u < n; u++) {
		if (color[u] == WHITE) dfs_visit(u);
	}

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

int main() {
	int u, k, v; // 訪問中の頂点u, 次数k, 次に訪問する頂点v

	cin >> n;
	for (int i = 0; i < n; i++) { // 配列0で初期化
		for (int j = 0; j < n; j++) M[i][j] = 0;
	}

	// 無向グラフを作成
	for (int i = 0; i < n; i++) {
		cin >> u >> k; // 頂点uと出次数kを入力
		u--; // 1 -> 0オリジンに変換
		for (int j = 0; j < k; j++) {
			cin >> v; // 次に訪問する未訪問頂点v入力
			v--; // 0オリジンへ変換
			M[u][v] = 1;
		}
	}

	dfs();

	return 0;
}