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+1)
	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++: // -*- 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<int, int>* const visited_;
  uint time_;
  
public:
  Graph(uint n) : n_(n),
                  g_(new uint[(n_*n_)]),
                  visited_(new std::pair<int, int>[n_])
  {
    std::fill(g_, g_+(n_*n_), 0u);
  }

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

  std::pair<int, int>* 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 = -1;
    }
  }

  void inner_dfs(uint i)
  {
    if (visited_[i].first != -1) {
      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 %d %d\n", i+1, visited[i].first+1, visited[i].second+1);
  }
}

// eof

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <list>
#define black 0
//#define red 1
#define white -1
#define maxn 110
using namespace std;

int tot = 0;
int book[maxn] = {}, t[maxn][2] = {};
list<int> map[maxn];

void dfs(int u)
{
	if (book[u] == white) return; 
	else
		if (book[u] == black)
		{
			t[u][0] = ++tot;
			for (list<int>::iterator it = map[u].begin(); it != map[u].end(); it++)
				dfs(*it-1);
			book[u] = white;
			t[u][1] = ++tot;
		}
	return;
}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int u,k,v;
		scanf("%d%d", &u,&k);
		u--;
		for (int i = 0; i < k; i++)
		{
			scanf("%d", &v);
			map[u].push_back(v);
		}
	}
	dfs(0);
	for (int i = 0; i < n; i++)
	{
		printf("%d %d %d\n", i + 1, t[i][0], t[i][1]);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int n,M[105][105],d[105],f[105],tt,P[105],nt[105];

int next(int u){
	for(int v=nt[u];v<n;v++){
		nt[u]=v+1;
		if(M[u][v]){
			return v;
		}
	}
	return -1;
}
void dfs_visit(int r){
	for(int i=0;i<n;i++){
		nt[i]=0;
	}
	stack<int> s;
	s.push(r);
	P[r]=1;
	tt++;
	d[r]=tt;
	while(s.size()!=0){
		int u= s.top();
		int v=next(u);
		if(v!=-1){
			if(P[v]==0){
				P[v]=1;
				tt++;
				d[v]=tt;
				s.push(v);
			}
		}
		else{
			P[u]=2;
			tt++;
			f[u]=tt;
			s.pop();
		}
	}
}

void dfs(){
	for(int i=0;i<105;i++){
		d[i]=f[i]=P[i]=0;
	}
	tt=0;
	for(int i=0;i<n;i++){
		if(P[i]==0){
			dfs_visit(i);
		}
	}
	for(int i=0;i<n;i++){
		printf("%d %d %d\n",i+1,d[i],f[i]);
	}
}

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

C++: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define MAX 101

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll visited[MAX], d[MAX], f[MAX], tt = 0;
vector<int> G[MAX];

void dfs(int u) {
  d[u] = ++tt;
  visited[u] = 1;
  rep(i, G[u].size()) {
    if(visited[G[u][i]] == 0) dfs(G[u][i]);
  }
  f[u] = ++tt;
}

signed main() {
	ll n;
  cin >> n;
  for(int i = 1; i <= n; i++) visited[i] = 0;
  rep(i, n) {
    ll u, k;
    cin >> u >> k;
    rep(j, k) {
      ll v;
      cin >> v;
      G[u].pb(v);
    }
  }

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

	return 0;
}