Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

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

static const int DFS_VISIT_NO   = 0;
static const int DFS_VISIT_NOW  = 1;
static const int DFS_VISIT_DONE = 2;

static int g_time = 0;
static int g_setime[100][2] = {0};

void DfsVisit(int graph[][100], int num, int node, vector<int> &state)
{
    int i;

    ++g_time;
    g_setime[node][0] = g_time;

    state[node] = DFS_VISIT_NOW;

    for (i = 0; i < num; i++) {
        if ((graph[node][i] == 1) && (state[i] != DFS_VISIT_DONE)) {
            DfsVisit(graph, num, i, state);
        }
    }

    state[node] = DFS_VISIT_DONE;

    ++g_time;
    g_setime[node][1] = g_time;

    return;
}


void DFS(int graph[][100], int num)
{
    int i;
    vector<int> state;

    for (i = 0; i < num; i++) {
        state[i] = DFS_VISIT_NO;
    }

    for (i = 0; i < num; i++) {
        if (state[i] == DFS_VISIT_NO) {
            DfsVisit(graph, num, i, state);
        }
    }

    for (i = 0; i < num; i++) {
        printf("%d %d %d\n", i+1, g_setime[i][0], g_setime[i][1]);
    }

    return;
}

int main(void)
{
    int i, j;
    int target, tnum, node;
    int num;
    int graph[100][100] = {0};

    scanf("%d", &num);

    for (i = 0; i < num; i++) {
        scanf("%d" "%d", &target, &tnum);
        --target;
        for (j = 0; j < tnum; j++) {
            scanf("%d", &node);
            --node;
            graph[target][node] = 1;
        }
    }

    DFS(graph, num);
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
#define WHITE 0
#define GRAY 1
#define BLACK 2
typedef long long LL;
const int MAXN = 110;
int n, mapp[MAXN][MAXN], color[MAXN], d[MAXN], f[MAXN], tt;

void dfs_visit(int u) {
	color[u] = GRAY;//参照したことを示す
	d[u] = ++tt; //発見した時間を示す　0からなので足してから
	for(int i = 0; i < n; i++) {
		if(mapp[u][i] == 1 && color[i] == WHITE) {//u,i間に辺があること,iが未探訪を確認
			dfs_visit(i);
		}
	}
	color[u] = BLACK;//uに関して終わったことを示す
	f[u] = ++tt; //終了した時間を示す　足してから

}

void dfs() {
	tt = 0;
	memset(color, 0, sizeof(color));//探訪情報をリセット
	for(int i = 0; i < n; i++) {
		if(color[i] == WHITE) {//未探訪なら探索
			dfs_visit(i);
		}
	}
	for(int i = 0; i < n; i++) {
		printf("%d %d %d\n", i+1, d[i], f[i]);
	}
}

int main() {
	int u, v, k;
	cin >> n;
	memset(mapp, 0, sizeof(mapp));//木情報をリセット
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
		u--; //0から考えているのでノードの番号を1減らす
		while(k--) {
			cin >> v;
			v--;
			mapp[u][v] = 1;//uとvに辺があることを示す
		}
	}
	dfs();
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

vector<vector<int>> v;
vector<bool> seen;
vector<int> d,f;
int t = 0;

void dfs(int u,int &t){
    t++;
    d[u] = t; // 初訪問時の時刻
    seen[u] = true;
    for(int i=0;i<v[u].size();i++){
        if(seen[v[u][i]]) continue;
        dfs(v[u][i],t);
    }
    t++;
    f[u] = t;
}

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

    v.resize(n+1);
    seen.resize(n+1);
    d.resize(n+1);
    f.resize(n+1);
    rep(i,n+1) seen[i] = false;

    rep(i,n){
        int u,k;
        cin >> u >> k;
        rep(j,k){
            int tmp;
            cin >> tmp;
            v[u].push_back(tmp);
        }
    }
    // 深さ優先探索で探索する.
    for(int i=1;i<=n;i++){
        if(seen[i])continue;
        dfs(i,t);
    }
    for(int i=1;i<=n;i++){
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define ll long long
typedef complex<double> P;

int main() {
  int n; cin >> n;
  int adj[n][n] = {};

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

  int d[n] = {};
  int f[n] = {};
  int t = 1;

  stack<int> st;
  st.push(0);

  while (!st.empty()) {
    int v = st.top();

    if(d[v] == 0) {
      d[v] = t;
    }

    for (int i = 0; i < n; i++) {
      if(adj[v][i] == 1 && d[i] == 0) {
        st.push(i);
        break;
      }
    }

    if(st.top() == v) {
      f[v] = t+1;
      st.pop();
    }

    t++;
  }

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

}

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) {
      if (visited_[i].first) continue;
      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)
  {
    std::stack<uint> s;
    s.push(i);
    visited_[i].first = time_++;
    auto last_visited = i;
  outer_loop:
    while (!s.empty()) {
      auto j = s.top();
      for (auto k = last_visited+1; k < n_; ++k) {
        if ((*this)[j][k] && !visited_[k].first) {
          s.push(k);
          visited_[k].first = time_++;
          goto outer_loop;
        }
      }
      s.pop();
      visited_[j].second = time_++;
      last_visited = j;
    }
  }
};

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