Go: package main

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

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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