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 <iostream>
#include <vector>
using namespace std;

int n;
vector<vector<int> > A;
vector<vector<int> > T;
int time = 0;

void dfs(int cur){ // cur????¨????
    // cur ????¨??????????????¨????
    time += 1;
    T[cur][0] = time;
    // ???????¢??????¨??¨???
    cerr << "visiting " << cur << " " << time << endl;

    for(int dst = 0; dst < n; ++dst){ // ??¨???????????? dst ????????????
        if(A[cur][dst] == 1 && T[dst][0] == -1){ // cur??????dst??????????????????,dst???????¨??????????
            dfs(dst);
        }
    }
    // cur ????¨????????????????????¨????
    time += 1;
    T[cur][1] = time;
    // ??¢??°?????????????????????????????? (?????¢??°)
    return; // ?????\???
}

int main(){
    cin >> n;
    vector<vector<int> > A(n, vector<int>(n, 0));
    vector<vector<int> > T(n, vector<int>(2, -1));
    for(int i=0; i<n; ++i){
        int k;
        cin >> k;
        // 1~n???index?????¨????????????????????????????????????1????????????0~n-1????????????
        k -= 1;
        int u;
        cin >> u;
        for(int j=0; j<u; ++j){
            int v;
            cin >> v;
            v -= 1;
            A[k][v] = 1;
        }
    }
    for(int i=0; i<n; ++i){
        if(T[i][0] == -1){
          dfs(i);
        }
    }
    for(int i=0; i<n; ++i){
        cout << i+1 << T[i][0] << T[i][1] << endl;
    }
}

C++: #include <cstdio>
#include <vector>
using namespace std;

const int maxn = 100;
vector<int> G[maxn + 5];
//int book[maxn + 5][maxn + 5];
int n;
int d[maxn + 5];
int f[maxn + 5];
int time = 0;


void dfs(int vertex) {
    d[vertex] = ++time;

    int len = G[vertex].size();
    for(int i = 0; i < len; i++) {
        if(!d[G[vertex][i]]) dfs(G[vertex][i]);
    }

    f[vertex] = ++time;
}

int main() {
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        int num;
        scanf("%d", &num);
        int count;
        scanf("%d", &count);


        while(count--) {
            int temp; scanf("%d", &temp);
            G[num].push_back(temp);
        }
    }
    for(int i = 1; i <= n; i++) {
        if(!d[i]) dfs(i);
    }

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

C++: #include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <complex>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int d[110], f[110];
vector<int> g[110];
int t;
bool used[110];
void solve(int i) {
    if (used[i]) return;
    used[i] = true;
    t++;
    d[i] = t;
    for (int j: g[i]) {
        solve(j);
    }
    t++;
    f[i] = t;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int id, u;
        cin >> id >> u;
        for (int j = 0; j < u; j++) {
            int a;
            cin >> a;
            g[i].push_back(a-1);
        }
    }
    t = 0;
    fill_n(used, 110, false);
    for (int i = 0; i < n; i++) {
        solve(i);
    }
    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
    return 0;
}

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

#define M 100
#define TRUE 10
#define WHITE 1
#define BLACK 2
#define GRAY 3
stack<int> T;
int n,t = 1,D[M + 1],F[M + 1],color[M + 1],N[M + 1][M + 1],Ni[M + 1];

int next(int v){
  for(int i = Ni[v];i <= n;i++){
    Ni[v] = i + 1;
    if(N[v][i] == TRUE) return i;
  }
  return -1;
}
  
void dsearch(int v){
  int top;
  
  T.push(v);
  color[v] = GRAY;
  D[v] = t++;

  while(!T.empty()){
    v = T.top();
    top = next(v);
    if(top != -1){
      if(color[top] == WHITE){
	color[top] = GRAY;
	D[top] = t++;
	T.push(top);
      }
    }
    else{
      T.pop();
      color[v] = BLACK;
      F[v] = t++;
    }
  }
}
  
int main (){
  int r,c,v;

  cin >> n;
  for(int i = 1;i <= n;i++){
    color[i] = WHITE;
    Ni[i] = 0;
  }
 
  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= n;j++){
      N[i][j] = 0;
    }
  }
  
  for(int i = 1;i <= n;i++){
    cin >> r >> c;
    for(int j = 1;j <= c;j++){
      cin >> v;
      N[r][v] = TRUE;
    }
  }
  for(int i = 1;i <= n;i++){
    if(color[i] == WHITE) dsearch(i);
  }
  for(int i = 1;i <= n;i++){
    cout << i << " "<< D[i] << " "<< F[i] << endl;
  }

  return 0;
}

C++: 
#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;


vector<int> G[105];
int d[105];
int f[105];
int tm = 1;
void dfs(int p){
    d[p]=tm;
    rep(i,G[p].size()){
        if(d[G[p][i]]==-1){
            tm++;
            dfs(G[p][i]);
        }
    }
    f[p] = tm++;
    return;
}
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        d[i]=-1;
        f[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    dfs(1);
    for(int i = 1;i <= n;i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }
}