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>

#define N_MAX 100

using namespace std;

int t = 1;
int adj_matrix[N_MAX][N_MAX];
int d[N_MAX];
int f[N_MAX];

void dfs(int v, int n)
{
    if (d[v] == 0) {
        d[v] = t;
        t++;
    }
    for (int i = 0; i < n; i++) {
        if (adj_matrix[v][i] != 0) {
            dfs(i, n);
        }
    }
    if (f[v] == 0) {
        f[v] = t;
        t++;
    }
}

int main()
{
    int n, u, k, v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        d[i] = 0;
        f[i] = 0;
    }

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

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

    dfs(0, n);

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

    return 0;
}

C++: #include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
#define lpp(i,n) for(int i = 0; i < n; i++)
int n;
int g[101][103];
void dfs(int v);
using namespace std;
int t = 0;
int main(){
  int u,k,v;
  cin >> n;
  lp(n) {
    cin >> u >> k;
    lpp(j,k) {
      cin >> v;
      g[u][v] = 1;
    }
  }
  int y = 1;
  while(y != 0){
    dfs(y);
    y = 0;
    lp(n) {
      if(g[0][i+1] == 0) {
	y = i+1;
	break;
      }
    }
  }
  lp(n) cout << i+1 << " " << g[i+1][101] << " " << g[i+1][102] << endl;
  return 0;
}
void dfs(int v) {
  g[0][v] = 1;
  g[v][101] = ++t;
  lp(n){
    if(g[v][i+1] == 1 && g[0][i+1] == 0){
      dfs(i+1);
    }
  }
  g[v][102] = ++t;
  /*
  int v;
  int t = 1;
  vector<int> st;
  int *visited = g[0];
  v = 1;
  visited[v] = 1;
  st.push_back(v);
  g[v][101] = t;
  while(!st.empty()) {
    lp(st.size()) cout << st[i]<<" ";cout<<endl;
    v = st.front();
    st.pop_back();
    lp(100) {
      if(g[v][i+1] == 1) {
	if(visited[i+1] == 0) {
	  visited[i+1] = 1;
	  st.push_back(i+1);
	  g[i+1][101] = ++t;
	}
      }
    }
    }*/
}

C++: #include<stdio.h>
struct
{
    int Top=0;
    int s[20000];
    bool Empty()
    {
        return Top==0;
    }
    void push(int x)
    {
        s[++Top]=x;
    }
    void pop()
    {
        Top--;
    }
    int top()
    {
        return s[Top];
    }
}S;
const int N=100;
const int bai=0;
const int hui=1;
const int hei=2;
int n,tu[N][N];
int fx[N],js[N],sum,nt[N],jilu[N];
int next(int u)
{
    for (int v=nt[u];v<n;v++)
    {
        nt[u]=v+1;
        if(tu[u][v]) return v;
    }
    return -1;
}
void DFS_visit(int r)
{

    S.push(r);
    jilu[r]=hui;
    fx[r]=++sum;
    while(!S.Empty())
    {
        int u=S.top();
        int v=next(u);
        if(v!=-1)
        {
            if(jilu[v]==bai)
            {
                jilu[v]=hui;
                fx[v]=++sum;
                S.push(v);
            }
        }
        else
        {
            S.pop();
            jilu[u]=hei;
            js[u]=++sum;    
        }
    }
}
void DFS()
{
    sum=0;
    for (int u=0;u<n;u++)
    {
        if(jilu[u]==bai)
            DFS_visit(u);
    }
    for (int i=0;i<n;i++)
    {
        printf("%d %d %d\n",i+1,fx[i],js[i]);
    }
}
int main()
{
    int u,k,v;
    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--;
            tu[u][v]=1;
        }
    }
    DFS();
    return 0;
}

C++: #include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
/*
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
*/

int table[101][101], time_table[101][2];
int common_time = 1, n;

void dfs(int node){
    if(time_table[node][0] == 0) time_table[node][0] = common_time++;
    else return;
    for(int i = 1; i <= n; i++){
        if(table[node][i] == 1) dfs(i);
    }
    time_table[node][1] = common_time++;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    int id, k, v;
    rep(i,n+1){
        rep(j,n+1) table[i][j] = 0;
        time_table[i][0] = 0;
        time_table[i][1] = 0;
    }
    rep(i,n){
        cin >> id >> k;
        rep(j,k){
            cin >> v;
            table[id][v] = 1;
        }
    }
    for(int i = 1; i <= n; i++){
        dfs(i);
    }
    for(int i = 1; i <= n; i++){
        cout << i << " " << time_table[i][0] << " " << time_table[i][1] << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int n,g[100][100],c[100],f[100],e[100],t=1;
void dfs(int now){
  c[now]=1;
  f[now]=t;
  t++;
  for(int i=0;i<n;i++) if(g[now][i]&&c[i]!=1){
      dfs(i);
      t++;
    }
  e[now]=t;
}
int main(){
 
  int a,b,tmp;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    for(int j=0;j<b;j++){
      cin>>tmp;
      g[a-1][tmp-1]=1;
    }
  }
  for(int i=0;i<n;i++) if(c[i]!=1){
      dfs(i);
      t++;
    }
 
  for(int i=0;i<n;i++) cout<<i+1<<" "<<f[i]<<" "<<e[i]<<endl;
 
  return 0;
 
}