Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

func next(u int) int {
	for v := nt[u]; v < n; v++ {
		nt[u] = v + 1
		if Adj[u][v] == 1 {
			return v
		}
	}
	return -1
}

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

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

using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int GREY = 1;
static const int BLACK = 2;

int n, m[N][N], color[N], nxtNei[N];
int t, t1[N], t2[N];

int nxt(int u){
	for (int v = nxtNei[u]; v < n; ++v) {
		nxtNei[u] = v + 1;
		if (color[v] == WHITE && m[u][v] == 1) {
			return v;
		}
	}
	return -1;
}

void dfs(int r){
	//for (int i = 0; i < n; ++i) nxtNei[i] = 0;
	stack<int> s;
	color[r] = GREY;
	s.push(r);
	t1[r] = t++;
	while (!s.empty()) {
		int u = s.top();
		int v = nxt(u);
		if (-1 == v){
			color[u] = BLACK;
			s.pop();
			t2[u] = t++;
			continue;
		}

		color[v] = GREY;
		s.push(v);
		t1[v] = t++;
	}
}

void search(){
	t = 1;
	for (int i = 0; i < n; ++i){
		color[i] = WHITE;
		nxtNei[i] = 0;
	}
	for (int i = 0; i < n; ++i) {
		if (color[i] == WHITE) dfs(i);
	}
	for (int i = 0; i < n; ++i){
		cout << i + 1 << " " << t1[i] << " " << t2[i] << endl;
	}
}


int main()
{
	cin >> n;

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

	for (int i = 0; i < n; ++i) {
		int u, d; cin >> u >> d;
		for (int j = 0; j < d; ++j) {
			int v; cin >> v;
			m[u - 1][v - 1] = 1;
		}
	}

	search();

	return 0;
}

C++: #include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<LL, LL>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<LL>;

//==============================================
int n, tt = 0;
vvi M;
vi D, F, searchStatus;

void antDfs(int u) {
	searchStatus[u] = 0;
	D[u] = ++tt;
	REP3(i, 1, n) {
		if (M[u][i] == 0) continue;

		if (searchStatus[i] == -1) {
			antDfs(i);
		}
	}
	F[u] = ++tt;
	searchStatus[u] = 1;
}

void print() {
	REP3(i, 1, n) {
		cout << i << " " << D[i] << " " << F[i] << "\n";
	}
}

void solve() {
	REP3(i, 1, n) searchStatus[i] = -1;

	REP3(i, 1, n) {
		if (searchStatus[i] == -1) {
			antDfs(i);
		}
	}

	print();
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	
	M.resize(n + 1, vi(n + 1));
	D.resize(n + 1);
	F.resize(n + 1);
	searchStatus.resize(n + 1);

	int u, k, v;
	REP3(i, 1, n) {
		cin >> u >> k;
		REP3(j, 1, k) {
			cin >> v;
			M[u][v] = 1;
		}
	}

	solve();
	return 0;
}

C++: #include<iostream>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 1

int n, M[N][N];
int color[N], s[N], f[N], ts; 

void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    s[u] = ++ts;
    for (v=0; v<n; v++) {
        if(M[u][v]==0){
            continue;
        }
        if (color[v]==WHITE) {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++ts;
}

void dfs() {
    int u;
    for (u=0; u<n; u++) {
        color[u] = WHITE;
    }
    ts = 0;
    //for (u=0; u<n; u++) {
    //    if (color[u]==WHITE){
            dfs_visit(0);
    //    }
    //}
    for (u=0; u<n; u++) {
        printf("%d %d %d\n", u+1, s[u], f[u]);
    }
}

int main() {
    int u, k, tmp;
    cin >> n;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            M[i][j] = 0;
        }
    }

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

C++: #include<iostream>
#include<cstdio>
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 u) {
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	for (v = 0; v < n; v++) {
		if (m[u][v] == 0)continue;
		if (color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}
void dfs() {
	int u;
	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;
	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;
}