Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

func next(u int) int {
	for v := nt[u]; v < n; v++ {
		nt[u] = v + 1
		if Adj[u][v] == 1 {
			return v
		}
	}
	return -1
}

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

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

C++: #include <bits/stdc++.h>
using namespace std;
#define WHITE 0
#define GRAY 1
#define BLACK 2

int M[101][101];
int d[101], f[101];
int searchPos[101];
int color[101];
int tt = 0;
int n;
stack<int> s;

int nextPoint(int curPoint){
    for(int i=searchPos[curPoint];i<n;++i){
        searchPos[curPoint] += 1;
        if(M[curPoint][i]==1 && color[i] == WHITE){
            return i;
        }
    }
    return -1;
}

void dfs(int point){
    d[point] = ++tt;
    color[point] = GRAY;
    while(1){
        int next = nextPoint(point);
        if(next != -1){
            dfs(next);
        }
        else{
            f[point] = ++tt;
            color[point] = BLACK;
            return;
        }
    }
}

int main(){
    int u, z, y;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        searchPos[i] = 0;
        color[i] = WHITE;
        for(int j=0;j<n;++j){
            M[i][j] = 0;
        }
    }
    for(int i=0;i<n;++i){
        cin >> u >> z;
        for(int j=0;j<z;++j){
            cin >> y;
            M[u-1][y-1] = 1;
        }
    }

    dfs(0);
    for(int i=0;i<n;++i){
        if(color[i]==WHITE){
            dfs(i);
        }
    }
    for(int i=0;i<n;++i){
        printf("%d %d %d\n",i+1,d[i],f[i]);
    }
    return 0;
}