Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

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

int d[101], f[101];
int color[101] = { 0 };
int M[101][101] = { 0 };

int times;

int cur;

stack<int> s;

int search_node(int n) {
    for (int node = 1; node <= n; ++node) {
        if (M[cur][node] == 1 && color[node] == WHITE) {
            return node;
        }
    }
    return -1;      // 見つからなかった場合
}

void visit_node(int target) {
    times += 1;
    s.push(target);
    cur = s.top();
    d[cur] = times;
    color[cur] = GRAY;
}

void reversal_node() {
    // ノードを戻っていく終了時刻を記入する処理+スタック削除
    times += 1;
    s.pop();
    f[cur] = times;
    color[cur] = BLACK;
    if (s.size() != 0) {
        cur = s.top();
    } else {
        cur = 0;
    }
}

bool black_judge(int n) {        // すべて探索済みか判定，初期化
    for (int node = 1; node <= n; ++node) {
        if (color[node] != BLACK) {
            s.push(node);
            cur = node;
            color[node] = GRAY;
            d[node] = times;
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    int u, k;
    int ver;
    times = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> u >> k;
        for (int j = 1; j <= k; ++j) {
            cin >> ver;
            M[i][ver] = 1;           // 隣接行列が得られる
        }
    }

    while (true) {
        times += 1;
        if (black_judge(n)) {
            break;                  // すべて探索済みなら完了
        }
        while (s.size() != 0) {
            int target;
            target = search_node(n);
            if (target == -1) {
                reversal_node();
            } else {
                visit_node(target);
            }
        }
    }
    
    for (int i = 1; i <= n; ++i) {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int arisutoteresu[200][200] = {0};
int imap[200][200] = {0};
int n,u,k[200];
int GetIt[200]={0};
int FinIt[200]={0};
bool used[200];
int fincou=1;
void dfs(int where,int find){
  fincou++;  
 
  GetIt[where]=find;
  if(k[where] != 0){
    for(int i=0;i<k[where];i++){
      if(!used[where]){
	dfs(imap[where][i],find+1);
	fincou++;
	used[where] = true;
      }
    }
  }
    FinIt[where] = fincou;
    
}

int main(){
 
  int ad;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> u;
    cin >> k[u];
    for(int j=0;j<k[u];j++){
      cin >> ad;
      arisutoteresu[u][ad] = 1;
      imap[u][j] = ad; 
    }
  }


  for(int j=0;j<n;j++)used[j] = false;
  dfs(1,1);

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

  return 0;
}

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

    return -1;
}

// スタックを用いた深さ優先探索
void dfs_visit(int r)
{
    int i;
    stack<int> S;

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

    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()
{
    int i, u;

    // 初期化
    for (i = 0; i < n; i++) {
        color[i] = WHITE;
    }
    tt = 0;

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

int main()
{
    int u, k, v;
    int i, j;

    cin >> n;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++) M[i][j] = 0;
    }

    for (i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

vector<int> grid[105];
vector<bool> seen(105, false);
P ans[105];
int t = 0;

void dps(int now)
{
    seen[now] = true;
    ++t;
    ans[now].first = t;
    for (int next : grid[now])
    {
        if (seen[next])
        {
            continue;
        }
        dps(next);
    }
    ++t;
    ans[now].second = t;
}

int main()
{
    int n;
    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;
            grid[u].push_back(v);
        }
    }
    for (int i = 1; i < n; i++)
    {
        if (!seen[i])
        {
            dps(i);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << i << ' ' << ans[i].first << ' ' << ans[i].second << endl;
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}