Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 101;
enum Color { WHITE = 0, GRAY, BLACK};
int n, tt{0};
vv(int, M, MAX, MAX, 0);
vi color(MAX, 0), d(MAX, 0), f(MAX, 0), nt(MAX, 0);
inline int next(int u) {
	rep(v, nt[u], n) {
		nt[u] = v + 1;
		if(M[u][v]) return v;
	}
	return -1;
}
inline void dfs_visit(int r) {
	deque<int> S;
	S.eb(r);
	color[r] = GRAY;
	d[r] = ++tt;
	int u, v;
	while(!S.empty()) {
		u = S.back();
		v = next(u);
		if(v != -1) {
			if(color[v] == WHITE) {
				color[v] = GRAY;
				d[v] = ++tt;
				S.eb(v);
			}
		} else {
			S.pop_back();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}
inline void dfs() {
	tt = 0;
	rep(u, 0, n) {
		if(color[u] == WHITE) dfs_visit(u);
	}
	rep(i, 0, n) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}
int main() {
	cin >> n;
	int u, k, v;
	rep(i, 0, n) {
		cin >> u >> k;
		--u;
		rep(j, 0, k) {
			cin >> v;
			M[u][--v] = 1;
		}
	}
	dfs();
	return 0;
}

C++: #include <stdio.h>

const int WHITE = -1;
const int GRAY = -2;
const int BLACK = -3;

int g[101][101], time1[101], time2[101], visit[101];
int n, u, k, m;
int t;

void dfs(int root)
{
	time1[root] = ++t;
 visit[root] = GRAY;
	for (int i = 1; i <= n; i++)
	{
		if (g[root][i] != -1 && visit[i] == WHITE)
		{
			visit[i] = GRAY;
			dfs(i);
		}
	}
	visit[root] = BLACK;
	time2[root] = ++t;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		visit[i] = WHITE;

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			g[i][j] = -1;

	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &u, &k);
		for (int j = 0; j < k; j++)
		{
			scanf("%d", &m);
			g[u][m] = 1;
		}
	}
	dfs(1);
	for (int i = 1; i <= n; i++)
	{
		printf("%d %d %d\n", i, time1[i], time2[i]);
	}

	return 0;
}

C++: // -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_11_B: Depth First Search

#include <algorithm>
#include <cstdio>
#include <stack>
#include <utility>

using uint = unsigned int;

class Graph {
  const uint n_;
  uint* const g_;
  std::pair<uint, uint>* const visited_;
  uint time_;
  
public:
  Graph(uint n) : n_(n),
                  g_(new uint[(n_*n_)]),
                  visited_(new std::pair<uint, uint>[n_])
  {
    std::fill(g_, g_+(n_*n_), 0u);
  }

  ~Graph()
  {
    delete[] g_;
    delete[] visited_;
  }
  
  uint* operator [](uint i) const { return g_+(n_*i); }

  std::pair<uint, uint>* visited() const { return visited_; }

  void dfs()
  {
    init_visited();
    for (auto i = 0u; i < n_; ++i) {
      inner_dfs(i);
    }
  }

private:
  void init_visited()
  {
    time_ = 0u;
    for (auto i = 0u; i < n_; ++i) {
      visited_[i].first = 0u;
    }
  }

  void inner_dfs(uint i)
  {
    if (visited_[i].first) {
      return;
    }
    visited_[i].first = time_++;
    for (auto j = 0u; j < n_; ++j) {
      auto k = (*this)[i][j];
      if (k) {
        inner_dfs(j);
      }
    }
    visited_[i].second = time_++;
  }
};

int main()
{
  uint n;
  std::scanf("%u", &n);

  Graph g(n);

  uint u, k, v;
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%u %u", &u, &k);
    for (auto j = 0u; j < k; ++j) {
      std::scanf("%u", &v);
      g[u-1][v-1] = 1;
    }
  }

  g.dfs();
  auto visited = g.visited();
  for (auto i = 0u; i < n; ++i) {
    std::printf("%u %u %u\n", i+1, visited[i].first+1, visited[i].second+1);
  }
}

// eof

C++: // Depth First Search
// 所要時間 x分
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()

int t = 0;
vector<vector<int> > graph;
vector<pair<int, int> > ans;
vector<bool> visit;

void dfs(int node, int pre = -1){
    if(visit[node]){
        return;
    }
    visit[node] = true;
    t++;
    ans[node].first = t;
    for(int i=0; i<graph[node].size(); ++i){
        dfs(graph[node][i], node);
    }
    t++;
    ans[node].second = t;
}

int main() {

    int n;
    cin >> n;
    graph.resize(n);
    ans.resize(n);
    visit.resize(n);
    rep(i, n){
        int u, k;
        cin >> u >> k;
        --u;
        rep(j, k){
            int v;
            cin >> v;
            --v;
            graph[u].push_back(v);  
        }
    }

    rep(i, n){
        dfs(i);
    }

    rep(i, n){
        cout << i+1 << " " << ans[i].first << " " << ans[i].second << endl;
    }

    return 0;
}

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

using Graph = std::vector<std::vector<int>>;

void dfs(std::vector<bool> &seen, Graph &g, int v, int &time, std::vector<int> &preOrder, std::vector<int> &postOrder){
    preOrder.at(v) = time;
    ++time;

    seen.at(v) = true;
    for(auto nextV : g.at(v)){
        if(seen.at(nextV)){
            continue;
        }
        dfs(seen, g, nextV, time, preOrder, postOrder);
    }

    postOrder.at(v) = time;
    ++time;
}

int main(){
    int n;
    std::cin >> n;

    Graph g(n);
    std::vector<int> preOrder(n), postOrder(n);
    for(int i = 0; i < n; ++i){
        int m, l;
        std::cin >> m >> l;
        for(int j = 0; j < l; ++j){
            int k;
            std::cin >> k;

            g.at(i).push_back(k - 1); 
//            g.at(k - 1).push_back(i); // for undirected graphs
        }
    }

    std::vector<bool> seen(n, false);
    int time = 1;
    for(int i = 0; i < n; ++i){
        if(seen.at(i)){
            continue;
        }

        dfs(seen, g, i, time, preOrder, postOrder);
    }

    for(int i= 0; i < n; ++i){
        std::cout << i + 1 << " " << preOrder.at(i) << " " << postOrder.at(i) << std::endl;
    }

    return 0;
}