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;

const int MAX = 101;

vector<int> G[MAX];
int d[MAX], f[MAX];
int *T;

void dfs(int u) {

    if (!d[u]) d[u] = ++(*T);

    for (int v : G[u]) {
        if (!d[v]) d[v] = ++(*T);
        dfs(v);
    }

    if (!f[u]) f[u] = ++(*T);
}

int main() {

    int n;
    cin >> n;

    int t = 0;
    T = &t;
    fill(d, d + MAX, 0);
    fill(f, f + MAX, 0);

    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            G[u].push_back(v);
        }
    }

    for (int i = 1; i <= n; i++) {
        if (!d[i]) dfs(i);
    }


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

C++: #include <iostream>
#include <map>
#include <vector>

using namespace std;
struct node {
    node() {};
    node(int i, int n, int* xs) : id {i}, ns {vector<int>(xs, xs+n)} {
        delete xs;
    };
    int id;
    vector<int> ns;
    int in_time;
    int out_time;
};

int dfs(map<int, node*> graph, int time, int id){
    node* n = graph[id];
    if(n->in_time > 0){
        return time;
    }
    n->in_time = ++time;
    vector<int> ns = n->ns;
    for(auto it = ns.begin(); it != ns.end(); ++it){
        time = dfs(graph, time, *it);
    }
    n->out_time = ++time;
    return time;
}

int main(){
    int n;
    cin >> n;
    map<int, node*> graph {};
    int st = 1000000000;
    for(int i = 0; i < n; ++i){
        int id;
        cin >> id;
        st = min(st, id);
        int k;
        cin >> k;
        int* ns = new int[k];
        for(int j = 0; j < k; ++j){
            cin >> ns[j];
        }
        graph[id] = new node(id, k, ns);
    }
    int time = 0;
    for(auto it = graph.begin(); it != graph.end(); ++it){
        pair<int, node*> p = *it;
        if(p.second->in_time){
            continue;
        }
        time = dfs(graph, time, p.first);
    }
    for(auto it = graph.begin(); it != graph.end(); ++it){
        pair<int, node*> p = *it;
        cout << p.first << ' ' << p.second->in_time << ' ' << p.second->out_time << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define WHITE 0
#define GRAY 1
#define BLACK 2
vector<vector<int>> M(100, vector<int>(100));
vector<int> C(100);
int n, tt;
vector<int> ST(100), PT(100);

int next(int u) {
  rep(i, n) {
    if (M.at(u).at(i) == 1 && C.at(i) == WHITE) {
      return i;
    }
  }
  return -1;
}

void dfs_visit(int u) {
  stack<int> S;
  S.push(u);
  ST.at(u) = ++tt;
  C.at(u) = GRAY;
  while (S.size() > 0) {
    int t = S.top();
    int v = next(t);
    if (v!=-1) {
      if (C.at(v) == WHITE) {
        S.push(v);
        ST.at(v) = ++tt;
        C.at(v) = GRAY;
      }
    } else {
      S.pop();
      PT.at(t) = ++tt;
      C.at(t) = BLACK;
    }
  }
}

void dfs() {
  tt = 0;
  rep(u, n) if (C.at(u) == WHITE) dfs_visit(u);
}

int main() {
  cin >> n;
  rep(i, n) {
    int id, k; cin >> id >> k;
    rep(j, k) {
      int num; cin >> num;
      M.at(id-1).at(num-1) = 1;
    }
  }
  dfs();

  rep(i,n) cout << i+1 << " " << ST.at(i) << " " << PT.at(i) << endl;
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
const int maxx = 110;
int n, m[maxx][maxx];
int u, num, v;
int d[maxx], f[maxx];
int flag[maxx];
int nowtime = 1;

void dfs(int u) {

	// ??\?????¶??´
	flag[u] = 1;
	d[u] = nowtime++;
	for (int i = 1; i <= n; i++) {
		if (flag[i] == 0 && m[u][i] == 1) {
			dfs(i);
		}
	}
	//????????¶??´
	f[u] = nowtime++;
}

int main()
{

	scanf("%d", &n);
	memset(m, 0, sizeof(m));
	memset(f, 0, sizeof(f));
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &u, &num);
		for (int j = 1; j <= num; j++) {
			scanf("%d", &v);
			m[u][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		if(flag[i] == 0)
			dfs(i);
	}
	for (int i = 1; i <= n; i++) {
		printf("%d %d %d\n", i, d[i], f[i]);
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
#include<vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
//using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<long long,int> P;


int n, t = 0;
vector<int> g[105];
bool seen[105];
int d[105], f[105];

void dfs(int v){
    seen[v] = true;
    d[v] = t;
    for(int nv : g[v]){
        if(seen[nv]) continue;
        t++;
        dfs(nv);
    }
    t++;
    f[v] = t;
}

int main(){
    cin >> n;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        rep(j, b){
            int c;
            cin >> c;
            g[a].push_back(c);
        }
    }
    rep(k, n) g[0].push_back(k + 1);

    memset(seen, 0, sizeof(seen));
    dfs(0);

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