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>
#include<stack>

using namespace std;

vector<int> G[100];
int n;
int t;
int vn,un;
int s[100],f[100];
int inf = 1<<21;
int tim=1;

void dfs(int u){
    //cout << u << " " << s[u] << " " << f[u] << endl;
    s[u] = tim;
    tim++;
    for(int i=0;i<G[u].size();i++){
        int v = G[u][i];
        if(s[v] == inf){
            dfs(v);
        }
    }
    f[u] = tim;
    tim++;
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> vn >> un;
        vn--;
        for(int j=0;j<un;j++){
            cin >> t;
            t--;
            //cout << t << " " << vn << endl;
            G[vn].push_back(t);
        }
    }
    fill(s,s+n,inf);
    fill(f,f+n,inf);
    //cout << s[2] << " " << f[3] << endl;
    for(int i=0;i<n;i++){
        if(f[i] == inf) dfs(i);
    }
    for(int i=0;i<n;i++){
        cout << i+1 << " " << s[i] << " " << f[i] << endl;
    }
    return 0;

}

C++: #include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

enum State {
    unseen, // 未訪問
    seen,   // 発見済み
    end     // 探索終了
};

vector<vector<int>> adj; // 隣接行列
int t = 0; // 時刻
int d[110];   // 頂点vを最初に発見した発見時刻　
int f[110];   // 頂点vの隣接リストを調べ終えた完了時刻
State s[110];

void dfs(int u) {
    ++t;
    d[u] = t;
    s[u] = State::seen;
    // uの隣接点を探索
    for (auto &v: adj[u]) {
        if (s[v] == State::unseen) {
            dfs(v);
        }
    }
    // uは探索済み
    s[u] = State::end;
    ++t;
    f[u] = t;
}

int main() {
    int n; cin >> n;
    adj.resize(n);
    rep(i, n) {
        int u, k; cin >> u >> k;
        --u;
        rep(j, k) {
            int v; cin >> v;
            --v;
            adj[i].emplace_back(v);
        }
    }

    // 初期化
    rep(i, n) {
        d[i] = INT_INF;
        f[i] = 0;
        s[i] = State::unseen;
    }

    // DFS
    rep(i, n) {
        if (s[i] == State::unseen) {
            dfs(i);
        }
    }

    // 出力
    rep(i, n) {
        cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

C++: #include <iostream>

using namespace std;

typedef pair<int, int> p;

int n,u,k,t;
int** v;
p* T;

void bfs(int pos) {
  // if visited
  if (T[pos].first) {
    return;
  }
  // check visit
  T[pos].first = ++t;

  int leng = v[pos][0];
  for (int i = 1; i <= leng; i++) {
    bfs(v[pos][i]);
  }
  T[pos].second = ++t;
}

int main() {
  cin >> n;

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

  T = new p[n+1];
  for (int i = 1; i <= n; i++) {
    T[i] = p(0, 0);
  }

  t = 0;
  bfs(1);

  for (int i = 1; i <= n; i++) {
    cout << i << " " << T[i].first << " " << T[i].second << endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
const int MAXN = 100;
int d[MAXN], f[MAXN], tt;
int n,color[MAXN], mat[MAXN][MAXN];
//0表示未访问，1表示正在访问，2表示访问完毕
void dfs_visit(int node)
{
	int i;
	color[node] = 1;
	d[node] = ++tt;  //记录最初的访问时间
	for (i = 0; i < n; i++)
	{
		if (mat[node][i] == 0)	continue;
		if (color[i] == 0)	dfs_visit(i);
	} 
	color[i] = 2;  
	f[node] = ++tt;  //访问结束
}

void dfs()
{
	int i;
	for (i = 0; i < n; i++)	color[i] = 0;  //初始化为未访问状态
	tt = 0; //从0开始计时
	for (i = 0; i < n; i++)
	{
		if (color[i] == 0)
			dfs_visit(i);
	}
	for (i = 0; i < n; i++)	printf("%d %d %d\n", i + 1, d[i], f[i]);
}



int main()
{
	int u,k,m;
	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", &m);
			mat[u][m - 1] = 1;
		}
	}
	dfs();
    return 0;
}

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

using namespace std;

int solve(vector<vector<int> >& V, vector<int>& d, vector<int>& f, int cur, int timestamp) {
  bool change = false;
  for (int i = 0; i < V[cur].size(); ++i) {
    int next = V[cur][i] - 1;
    if (d[next] == 0) {
      ++timestamp;
      d[next] = timestamp;
      timestamp = solve(V, d, f, next, timestamp);
    }
  }
  ++timestamp;
  if (f[cur] == 0)
      f[cur] = timestamp;
  return timestamp;
}

int main(int argc, char* argv[]) {
  int n;
  cin >> n;

  vector<vector<int> > V(n);
  for (int i = 0; i < n; ++i) {
    int u, k;
    cin >> u >> k;
    vector<int> tmp(k);
    for (int j = 0; j < k; ++j)
      cin >> tmp[j];
    V[u - 1] = tmp;
  }

  vector<int> d(n);
  vector<int> f(n);
  int timestamp = 0;
  for (int i = 0; i < n; ++i) {
    if (d[i] == 0) {
      ++timestamp;
      d[i] = timestamp;
      timestamp = solve(V, d, f, i, timestamp);
    }
  }

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

  return 0;
}