Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include <iostream>
#include <stack>
#define NUM 100
using namespace std;
int process_time;

typedef enum
{
    PRE,
    NOW,
} NodeStatus;

struct Node
{
    int num;
    int *p;
    int d;
    int f;

    int status;
    void Set(int num);
};

void Node::Set(int n)
{
    this->num = n;
    this->status = PRE;
    p = new int[n];
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
}

void Search(Node *vertex, int start)
{
    stack<Node *> st;

    st.push(&vertex[start]);
    vertex[start].status = NOW;
    vertex[start].d = process_time;
    while (!st.empty())
    {
        process_time++;
        int k = st.top()->num;
        int i;
        for (i = 0; i < k; i++)
        {
            if (vertex[st.top()->p[i]].status == PRE)
            {
                break;
            }
        }
        if (i == k)
        {
            Node *v;
            v = st.top();
            st.pop();
            v->f = process_time;
        }
        else
        {
            st.push(&vertex[st.top()->p[i]]);
            st.top()->d = process_time;
            st.top()->status = NOW;
        }
    }
}

int main()
{
    int n;
    Node vertex[NUM];
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        int k, u;
        cin >> u >> k;
        vertex[u].Set(k);
    }

    process_time = 1;
    Search(vertex, 1);

    int count;
    for (count = 1; count <= n; count++)
    {
        if (vertex[count].status == PRE)
        {
            break;
        }
    }
    if (count != n + 1)
    {
        process_time++;
        Search(vertex, count);
    }

    for (int i = 1; i <= n; i++)
    {
        cout << i << ' ' << vertex[i].d << ' ' << vertex[i].f << endl;
    }
    /*for (int i = 1; i <= n; i++) //1オリジン
    {
        for (int j = 0; j < vertex[i].num; j++)
        {
            cout << vertex[i].p[j] << ' ';
        }
        cout << endl;
    }*/

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;
int t=1;
v<int> d,f;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
  if(seen[v]==true) return;
  seen[v] = true; // v を訪問済にする
  d[v]=t++;
  // v から行ける各頂点 next_v について
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue; // next_v が探索済だったらスルー
    dfs(G, next_v); // 再帰的に探索
  }
  f[v]=t++;
}

signed _main() {
  // 頂点数と辺数
  int N; cin >> N;

  // グラフ入力受取 (ここでは無向グラフを想定)
  Graph G(N);
  d.resize(N);
  f.resize(N);
  for (int i = 0; i < N; ++i) {
    int u, k; cin >> u >> k;
    u--;
    rep(j,k){
      int v; cin >> v;
      v--;
      G[u].push_back(v);
    }
  }

  // 頂点 0 をスタートとした探索
  seen.assign(N, false); // 全頂点を「未訪問」に初期化
  rep(i,N){
    dfs(G,i);
  }
  rep(i,N){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#define N 100
#define  GRAY 1
#define BLACK 2
using namespace std;
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] == 0)
    {
      dfs_visit(v);
    }
}
  color[u] = BLACK;
  f[u] == ++tt;
}
void dfs()
{
  int u;
  for(u = 0;u<n;u++)
     color[u] = 0;
  tt = 0;
  for(u = 0;u<n;u++)
  {
    if(color[u] == 0) 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(int i = 0;i<n;i++)
    for(int j = 0;j<n;j++)
        M[i][j] = 0;
  for(int i =0;i<n;i++)
   {
     scanf("%d %d",&n,&k);
     u--;
     for(int j = 0;j<n;j++)
       {
         scanf("%d",&v);
         v--;
         M[u][v] = 1;
       }
   }
   dfs();
  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;
int go[102];
inline void search(int t) {
	if(!tim[t][0]) tim[t][0] = ct++;
	go[t] = 1;
	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 = 2; i <= n; i++) {
		if (!go[i]) {
			st.push(i);
			search(i);
	}
	for (int i = 1; i <= n; i++) {
		cout << i << " " << tim[i][0] << " " << tim[i][1] << endl;
	}
	return 0;
}