Go: package main

/*
深さ優先探索
*/

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

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n+1)
	for i := 1; i < n+1; i++ {
		ints := eGetInts(scanner)
		num, vcount := ints[0], ints[1]
		g[i] = make([]int, vcount)
		for j := 0; j < vcount; j++ {
			g[num][j] = ints[j+2]
		}
	}
	hist := make([]struct{ d, f int }, n+1)
	t := 0
	var visit func(int)
	visit = func(num int) {
		if hist[num].d == 0 {
			stack := []int{}
			t++
			hist[num].d = t
			stack = append(stack, num)
			for len(stack) > 0 {
				// トップを訪問する
				top := stack[len(stack)-1]
				for i := 0; i < len(g[top]); i++ {
					if hist[g[top][i]].d == 0 {
						t++
						hist[g[top][i]].d = t
						stack = append(stack, g[top][i])
						goto endloop
					}
				}
				// 訪問場所がなくなったら
				// pop
				stack = stack[0 : len(stack)-1]
				t++
				hist[top].f = t
			endloop:
			}
		}
	}
	for i := 1; i < n+1; i++ {
		visit(i)
	}
	for i := 1; i < n+1; i++ {
		fmt.Println(i, hist[i].d, hist[i].f)
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

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

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

int time_stamp;
int M[N+1][N+1];

void dfs(int n, int vertex, int d[], int f[], int color[]) {  
  color[vertex] = GRAY;
  d[vertex] = ++time_stamp;
  for (int i = 1; i <= n; i++) {    
    if (M[vertex][i] && color[i] == WHITE) {
      dfs(n, i, d, f, color);
    }
  }
  color[vertex] = BLACK;
  f[vertex] = ++time_stamp;
}

void search(int n, int d[], int f[], int color[]) {
  // 初期状態
  for (int i = 1; i <= n; i++) color[i] = WHITE;
  time_stamp = 0;
  // dfs
  for (int i = 1; i <= n; i++) {
    if (color[i] == WHITE) {
      dfs(n, i, d, f, color);
    }
  }
}

int main() {
  int i, j, n, u, k, v, d[N+1], f[N+1], color[N+1];
  
  cin >> n;
  // 隣接行列を取得
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      M[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    for (j = 0; j < k; j++) {
      cin >> v;
      M[u][v] = 1;
    }
  }

  search(n, d, f, color);

  for (i = 1; i <= n; i++) cout << i << " " << d[i] << " " << f[i] << endl;    

  return 0;
}

C++: #include <cstdio>

typedef struct Node {
    int id;
    int d;
    int f;
    int count;
} Node;


int count(int id, int now, Node *node, int a[101][100]){
    if(node[id].d == 0) node[id].d = now;
    if(node[id].f != 0) return now - 1;
    if(node[id].count == 0){
        node[id].f = now + 1;
        return node[id].f;
    }
    for(int i = 0; i < node[id].count; ++i){
        int nextId = a[id][i];
        now = count(nextId, now + 1, node, a);
    }
    node[id].f = now + 1;
    return node[id].f;
}

int main(){
    int n;
    std::scanf("%d", &n);
    Node node[101];
    int a[101][100];
    for(int i = 1; i <= n; ++i){
        int id;
        std::scanf("%d", &id);
        node[id].id = id;
        std::scanf("%d", &node[id].count);
        for(int j = 0; j < node[id].count; ++j){
            std::scanf("%d", &a[i][j]);
        }
    }
    count(1, 1, node, a);
    for(int i = 1; i <= n; ++i){
        std::printf("%d %d %d\n", node[i].id, node[i].d, node[i].f);
    }

    return 0;
}

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

int time1 = 0;
int a[110][110] = {};
int d[110] = {};
int f[110] = {};
int n;
int p;

void dfs(int cur){
  if(d[cur]==0){
    d[cur] = time1;
  }
  time1 += 1;
  f[cur] = time1;

  for(int dst=1;dst<=n;dst++){
    if(a[cur][dst]==1&&d[dst]==0){
      a[cur][dst]=2;
      dfs(dst);
    }
  }
  for(int k=1;k<=n;k++){
    if(a[k][cur]==2){
      a[k][cur]=1;
      p+=1;
      dfs(k);
    }else{
      p=0;
    }
  }
  if(p==0){
    for(int k=1;k<=n;k++){
      if(d[k]==0){
	time1+=1;
	dfs(k);
      }
    }
  }
}

int main(){
  cin>>n;
  for(int i=1;i<=n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v;
      cin>>v;
      a[i][v]=1;
    }
  }
  time1 += 1;
  dfs(1);
  for(int k=1;k<=n;k++){
    cout<<k<<" "<<d[k]<<" "<<f[k]<<endl;
  }
}

C++: #include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
void func(int);
int n,k[101],v[101][100],d[101],f[101],cnt;
int flg[101];
int main(void)
{
	int i,u,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	{
		scanf("%d %d",&u,&k[i]);
		for(j=0;j<k[i];j++)	scanf("%d",&v[i][j]);
	}
	for(i=1;i<=n;i++)	flg[i]=0;
	cnt=0;
	for(i=1;i<=n;i++)	{
		if(flg[i]==0)		func(i);
	}
	for(i=1;i<=n;i++)	printf("%d %d %d\n",i,d[i],f[i]);
	return 0;
}
void func(int nn)
{
	int i;
	cnt++;	
	d[nn]=cnt;
	flg[nn]=1;
	for(i=0;i<k[nn];i++)	{
		if(flg[v[nn][i]]==0)	{
			func(v[nn][i]);
		}
	}
	cnt++;
	f[nn]=cnt;
}

C++: #include <bits/stdc++.h>
 
using namespace std;

vector<vector<int>> g;
vector<int> s, e;

void dfs(int v, int& t) {
    if (s[v]) return;
    s[v] = t++;
    for (auto& x : g[v]) {
        dfs(x, t);
    }
    e[v] = t++;
}

int main() {
    int n; cin >> n;
    g.resize(n); s.resize(n); e.resize(n);
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k; u--;
        while (k--) {
            int v; cin >> v; v--;
            g[u].push_back(v);
        }
        sort(g[u].begin(), g[u].end());
    }
    int t = 1;
	for (int i = 0; i < n; i++) dfs(i, t);
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << s[i] << " " << e[i] << endl;
    }
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<ll> node;
};

ll N;
Vertex V[105];
pll ans[105];

void dfs(ll idx, ll &time) {
    ans[idx].first = time++;
    for (auto &nxt:V[idx].node) {
        if (ans[nxt].first > 0)
            continue;
        dfs(nxt, time);
    }
    ans[idx].second = time++;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) {
        ll n, k;
        cin >> n >> k;
        n--;
        REP(j, k) {
            ll v;
            cin >> v;
            v--;
            V[n].node.push_back(v);
        }
    }
    REP(i, N) {
        ans[i] = pll(0, 0);
    }
    ll time = 1;
    REP(i, N) {
        if (ans[i].first > 0)
            continue;
        dfs(i, time);
    }
    REP(i, N) {
        cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}