Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	g := graph{}
	g.ee = make([]Edges, n)
	g.visited = make([]bool, n)
	g.found = make([]int, n)
	g.leave = make([]int, n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner) - 1
		k := getNextInt(scanner)
		for j := 0; j < k; j++ {
			v := getNextInt(scanner) - 1
			g.ee[u] = append(g.ee[u], Edge{
				to: v,
				id: u,
			})
		}
	}
	for i := 0; i < n; i++ {
		sort.Sort(g.ee[i])
	}
	for i := 0; i < n; i++ {
		if g.visited[i] {
			continue
		}
		g.dfs(i)
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", i+1, g.found[i], g.leave[i]))
	}
}

// Edge ...
type Edge struct {
	to, id int
}

type Edges []Edge

func (a Edges) Len() int           { return len(a) }
func (a Edges) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Edges) Less(i, j int) bool { return a[i].id < a[j].id }

type graph struct {
	ee           []Edges
	t            int
	n            int
	visited      []bool
	found, leave []int
}

func (g *graph) dfs(i int) {
	g.visited[i] = true
	g.t++
	g.found[i] = g.t
	for _, e := range g.ee[i] {
		if g.visited[e.to] {
			continue
		}
		g.dfs(e.to)
	}
	g.t++
	g.leave[i] = g.t
}

C++: #include<bits/stdc++.h>
using namespace std;
const int MAXN =  100+7;
struct node {
    int id;
    node* next;
};
node* g[MAXN];
bool visit[MAXN];
int d[MAXN];
int f[MAXN];
int mytime;
stack<int> s;
void dfs(int i){
    node* p = g[i];
    while(p->next!=NULL){
        p=p->next;
        if(visit[p->id]==false){
            s.push(p->id);
            mytime++;
            d[p->id] = mytime;
            visit[p->id] = true;
            dfs(p->id);
        }

    }
    s.pop();
    mytime++;
    f[i] = mytime;

}
int main() {
//    freopen("../in.txt", "r", stdin);
    memset(visit, false, sizeof(visit));
    int n;
    scanf("%d", &n);
    int i;
    for(i = 1; i <= n; i++) {
        g[i] = (node*)malloc(sizeof(node));
        g[i]->next = NULL;
    }
    for(i = 0; i < n; i++) {
        int num;
        int k;
        scanf("%d", &num);
        scanf("%d", &k);
        int j;
        for(j = 0; j < k; j++) {
            int r;
            scanf("%d", &r);
            node* t = (node*)malloc(sizeof(node));
            t->id = r;
            t->next = NULL;
            node* p = g[num];
            while(p->next != NULL) p = p->next;
            p->next = t;
        }
    }
    mytime = 0;
    while(true){
        int u;
        int g = -1;
        for(u = 1; u <= n; u++){
            if(visit[u]==false){
                g = u;
                break;
            }
        }
        if(g==-1){
            break;
        }
        s.push(g);
        mytime++;
        d[g] = mytime;
        visit[g] = true;
        dfs(g);
    }

    for(i = 1; i <= n ; i++){
        printf("%d %d %d\n", i, d[i], f[i]);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<vector<int>> to(n);
   rep(i, 0, n) {
      int u, k;
      cin >> u >> k;
      u--;
      rep(j, 0, k) {
         int v;
         cin >> v;
         v--;
         to[u].push_back(v);
      }
   }
   vector<int> d(n), f(n), color(n);
   int t = 0;
   function<void(int)> dfs = [&](int u) {
      if (color[u] != 0) return;
      color[u] = 1;
      d[u] = ++t;
      for (int i = 0; i < to[u].size(); i++) {
         if (color[to[u][i]] == 0) {
            dfs(to[u][i]);
         }
      }
      color[u] = 2;
      f[u] = ++t;
   };
   rep(i, 0, n) dfs(i);
   rep(i, 0, n) printf("%d %d %d\n", i + 1, d[i], f[i]);
   return 0;
}

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 <iostream>

using namespace std;

int n;
int A[110][110];
int d[110];
int f[110];
string color[110];
int t = 0;

void dfs_visit(int u) {
  color[u] = "GRAY";
  d[u] = ++t;
  for (int v = 0; v < n; v++) {
    if (A[u][v] == 1 && color[v] == "WHITE") {
      dfs_visit(v);
    }
  }
  color[u] = "BLACK";
  f[u] = ++t;
}

void dfs() {
  // color 初期化
  for (int i = 0; i < n; i++) {
    color[i] = "WHITE";
  }
  for (int u = 0; u < n; u++) {
    if (color[u] == "WHITE") {
      dfs_visit(u);
    }
  }
}

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

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