Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

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;
}

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

using namespace std;

map<int, vector<int>> V;
map<int, int> pre;
map<int, int> post;
int t = 1;

int _DFS(int v, vector<bool> &visited) {
  pre[v] = t;
  ++t;
  for (int out_nbr_id : V[v]) {
    if (!visited[out_nbr_id]) {
      visited[out_nbr_id] = true;
      _DFS(out_nbr_id, visited);
    }
  }
  post[v] = t;
  ++t;
}

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

  vector<bool> visited(n, false);

  cin.ignore();

  for (string line; getline(cin, line);) {
    istringstream is{line};
    int id, n_nbrs, nbr;
    is >> id >> n_nbrs;
    vector<int> out_nbrs;
    while (is >> nbr)
      out_nbrs.push_back(nbr);
    V[id] = out_nbrs;
  }

  for (auto vadj : V) {
    if (!visited[vadj.first]) {
      visited[vadj.first] = true;
      _DFS(vadj.first, visited);
    }
  }

  for (auto vadj : V) {
    int id = vadj.first;
    cout << id << " " << pre[id] << " " << post[id] << endl;
  }
}

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

using namespace std;

const int WHITE = 0, GREY = 1, BLACK = 2;

struct DFS {
    int n;
    vector<vector<int>> g;
    vector<int> color;
    vector<int> dt;
    vector<int> ft;
    int ct = 1;
 
    DFS(int n) : n(n) {
        g.assign(n, vector<int>());
        color.assign(n, WHITE);
        dt.assign(n, -1);
        ft.assign(n, -1);
    }
    
    void solve() {
        for (int i = 0; i < n; i++) {
            if (color[i] == WHITE) {
                dfs(i);
            }
        }
    }
    
    void dfs(int u) {
        //cout << "visit " << u << endl;
        color[u] = GREY;
        dt[u] = ct++; 
        for (int v : g[u]) {
            if (color[v] == WHITE) {
                dfs(v);
            }
        }
        ft[u] = ct++;
        color[u] = BLACK;
    }
    
    void addEdge(int u, int v) {
        g[u].push_back(v);
    }
    
    void printGraph() {
        for (int i = 0; i < n; i++) {
            cout << i << ": ";
            for (int v : g[i]) {
                cout << v << " ";
            }
            cout << endl;
        }
    }
        
};


int main() {   
    int n;
    cin >> n;
    DFS dfs(n);
   
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            v--;
            dfs.addEdge(u, v);
        }  
    }
    
    //dfs.printGraph();
    
    dfs.solve();
    
    for (int i = 0; i < n; i++) {
        cout << (i + 1) << " " << dfs.dt[i] << " " << dfs.ft[i] << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstring>
#define N 101

using namespace std;

int visited[N], discovery[N], finish[N], tt, n;
vector<int> G[N];

void dfs(int u) {
    visited[u] = 1;
    discovery[u] = ++tt;
    for (int i = 0; i < G[u].size(); i++) {
        if (visited[G[u][i]] == 0) {
            dfs(G[u][i]);
        }
    }
    finish[u] = ++tt;
}

int main() {
    int u, k, v;

    cin >> n;

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

    for (int i = 0; i < n; i++) {
        if (visited[i] == 0) {
            dfs(i);
        }
    }

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

    return 0;
}