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 "memory.h"
#include <stack>

using namespace std;

bool matrix[100][100];
int n;

int next(int k){
	for(int i = 0; i < n; i++){
		if(matrix[k][i] == true)
			return i + 1;
	}
	return false;
}

int main(){
	int index, temp, num, current, count = 1;
	int start_end[100][2];
	stack<int> back;

	memset(matrix, 0, sizeof(matrix));
	memset(start_end, 0, sizeof(start_end));

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> index >> num;
		while(num--){
			cin >> temp;
			matrix[index-1][temp-1] = true;
		}
	}
	back.push(0);
	current = 0;
	while(!back.empty()){
		int r;
		r = next(current);
		if(start_end[current][0] == 0){
			start_end[current][0] = count;
			count++;
		}
		if(r){
			matrix[current][r-1] = false;
			back.push(current);
			current = r - 1;
		}
		else{
			if(start_end[current][1] == 0){
				start_end[current][1] = count;
				count++;
			}
			current = back.top();
			back.pop();
		}
		
	}
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << start_end[i][0] << " " << start_end[i][1] << endl;
	}

	system("pause");

}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#define N 2000

using namespace std;
vector<vector<int> > pa;
vector<vector<int> > ch;
int first[N] = {0};
int second[N] = {0};
int timestamp = 0;
void dfs(int x) {
    if (ch[x].empty()) {
        return;
    } else {
        for (int i = 0; i < ch[x].size(); i++) {
            if (first[ch[x][i]] * second[ch[x][i]] == 0) {
                timestamp++;
                first[ch[x][i]] = timestamp;
                dfs(ch[x][i]);
                timestamp++;
                second[ch[x][i]] = timestamp;
            }
        }
        return;
    }
}
int main() {
    int n;
    cin >> n;
    int temp = n;
    pa.clear(); pa.resize(N + 5);
    ch.clear(); ch.resize(N + 5);
    while (temp--) {
        int u, k, v;
        cin >> u >> k;
        for (int i = 0; i < k; i++) {
            cin >> v;
            pa[v].push_back(u);
            ch[u].push_back(v);
        }
    }
    int an = 0;
    for (int i = 1; i <= n; i++) {
        if (pa[i].empty()) {
            an = i;
            continue;
        }
        if (ch[i].empty()) {
            continue;
        }
        sort(pa[i].begin(), pa[i].end(), less<int>());
        sort(ch[i].begin(), ch[i].end());
    }
    timestamp++;
    first[an] = timestamp;
    dfs(an);
    timestamp++;
    second[an] = timestamp;
    for (int i = 1; i <= n; i++) {
        cout << i << ' ' << first[i] << ' ' << second[i] << '\n';
    }
}

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

#define MAX 100

stack<int> G;
int Graph[MAX+1][MAX+1];
int result[MAX+1][2];
int n;
int cnt = 0;

void dfs(int idx) {
    bool bl = false;
    for(int i=1; i<=n; i++) {
        //もし一つでも残っているノードがあればpushする
        if(Graph[idx][i]==1) {
            Graph[idx][i] = 0;
            //cout << "push: " << i << endl;
            cnt++;
            result[i][0] = cnt;
            G.push(i);
            dfs(i);
            bl = true;
        }
    }
    //一つも残っていなかったらpopする
    if(bl==false) {
        //cout << "pop: " << G.top() << endl;
        cnt++;
        result[G.top()][1] = cnt;
        G.pop();
        if(G.empty()) {
            return;
        }
        else {
            dfs(G.top());
        }
    }
}

int main() {
    int idx, g_num, a;

    cin >>n;
    for(int i=0; i<n; i++) {
        cin >> idx >> g_num;
        for(int j=0; j<n; j++) {
            Graph[idx][j] = 0;
        }
        for(int j=0; j<g_num; j++) {
            cin >> a;
            Graph[idx][a] = 1;
        }
    }
    G.push(1);
    cnt++;
    result[1][0] = cnt;
    cout << "push: " << 1 << endl;
    dfs(1);

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

    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int G[101][101];
bool Memo[101];
int d[101];
int f[101];
int count1;

void dfs(int i, int n) {
  if (Memo[i]) {
    count1++;
    d[i] = count1;
    Memo[i] = false;
    for (int j = 0; j < n; j++) {
      if (G[i][j] == 1) {
        dfs(j,n);
      }
    }
    count1++;
    f[i] = count1;
  }
}

int main() {
  int n;
  scanf("%d",&n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      G[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int row,col;
    scanf("%d %d",&row,&col);
    for (int j = 0; j < col; j++) {
      int d;
      scanf("%d",&d);
      G[row - 1][d - 1] = 1;
    }
  }
  for (int i = 0; i < n; i++) Memo[i] = true;
  count1 = 0;
  for (int i = 0; i < n; i++) {
    if (Memo[i]) dfs(i,n);
  }
  for (int i = 0; i < n; i++) printf("%d %d %d\n",i+1,d[i],f[i]);
  return 0;
}