Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

C++: #include <bits/stdc++.h>
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;
int nt[N];

int next(int u){//ntってなに？？現在地？
	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] = 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;
	}
	tt = 0;

	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;

	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;
		u--;
		for ( int 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++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	void dfs(int now, vector<vector<int>>& path, vector<int>& find, vector<int>& finish, int& time) {
		find[now] = time++;
		REP(i, path[now].size()) {
			int t = path[now][i];
			if (find[t] < 0) {
				dfs(t, path, find, finish, time);
			}
		}
		finish[now] = time++;
	}

	void solve() {
		IOS;
		int n;
		cin >> n;
		vector<vector<int>> path(n);
		REP(i, n) {
			int u, k;
			cin >> u >> k;
			u--;
			REP(j, k) {
				int v;
				cin >> v;
				v--;
				path[u].push_back(v);
			}
		}
		vector<int> visit(n, 0);
		vector<int> find(n, -1);
		vector<int> finish(n, -1);
		int time = 1;
		REP(i, n) {
			if (find[i] < 0) {
				dfs(i, path, find, finish, time);
			}
		}
		REP(i, n) {
			put(i + 1, find[i], finish[i]);
		}
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}

C++: #include<stdio.h>
#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;
    
    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++: #include <iostream>
using namespace std;

enum Color {
	WHITE,
	GRAY,
	BLACK,
};

class dfs {
public:
	dfs(bool matrixT[][100], Color colorT[], int ts_F[], int ts_L[], int verNum) {
		for (int i = 0; i < verNum; i++) {
			for (int j = 0; j < verNum; j++)
				matrixTable[i][j] = matrixT[i][j];
		}
		verNumber = verNum;
	}

	void DFS(int nowVerVal) {
		colorTable[nowVerVal] = GRAY;
		++ttl;
		ts_first[nowVerVal] = ttl;

		for (int nextVer = 0; nextVer < verNumber; nextVer++) {
			if (matrixTable[nowVerVal][nextVer] == false) continue;
			if (colorTable[nextVer] != WHITE) continue;
			DFS(nextVer);
		}
		colorTable[nowVerVal] = BLACK;
		++ttl;
		ts_last[nowVerVal] = ttl;
	}

	void DFS_Init() {
		ttl = 0;
		for (int i = 0; i < verNumber; i++)
			colorTable[i] = WHITE;

		for (int i = 0; i < verNumber; i++)
			if (colorTable[i] == WHITE) DFS(i);
	}

	void print() {
		for (int i = 0; i < verNumber; i++) {
			cout << i + 1 << " " << ts_first[i] << " " << ts_last[i] << endl;
		}
	}
private:
	bool matrixTable[100][100];
	Color colorTable[100];
	int ts_first[100];
	int ts_last[100];
	int verNumber;
	int ttl;
};

int main() {
	int verNum; //num??????????????°???value????????????????????????????????¨???
	bool matrixTable[100][100]; //???????????¨??????????????????
	Color colorTable[100];
	int timeStamp_first[100];
	int timeStamp_last[100];
	cin >> verNum;

	for (int i = 0; i < verNum; i++)
		for (int j = 0; j < verNum; j++) {
			matrixTable[i][j] = false;
		}

	for (int i = 0; i < verNum; i++) {
		int verVal, nextVerNum;
		cin >> verVal >> nextVerNum;
		for (int j = 0; j < nextVerNum; j++) {
			int nextVerVal;
			cin >> nextVerVal;
			//0?????????????????´???
			matrixTable[verVal - 1][nextVerVal - 1] = true;
		}
	}

	dfs* d = new dfs(matrixTable, colorTable, timeStamp_first, timeStamp_last, verNum);
	d->DFS_Init();
	d->print();

	return 0;
}

C++: #include<iostream>
using namespace std;
int visit[101],d[101],f[101],t;
//   訪問状態     発見    完了
int n,M[101][101];
const int WHITE=0; //未訪問
const int GRAY=1;  //訪問はした
void dfs(int u){
  visit[u]=GRAY; //訪問はした
  d[u]=++t; //発見した時刻
  for(int v=0;v<n;v++){
    if(M[u][v]==0) continue; //辺がない
    if(visit[v]==WHITE) dfs(v);
  }
  f[u]=++t; //訪問完了時刻
}
int main(){
  int u,v,k;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(int j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  for(int i=0;i<n;i++){
    if(visit[i]==WHITE) //訪問していないか
      dfs(i); //iを始点に
  }
  for(int i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}