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++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits.h>
using namespace std;
bool flag[101];
int d[101];
int f[101];
vector<int> v[101];
int t;
void dfs(int node){
	flag[node] = true;
	d[node] = t;
	bool finished = true;
	if (finished && f[node] == 0) f[node] = t;
	for (int i = 0; i < v[node].size(); ++i){
		int tmp = v[node][i];
		if (!flag[tmp]){
			++t;
			dfs(tmp);
			++t;
		}
	}
	f[node] = t;
}
int main(){
	int n; scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		int u, k; scanf("%d %d",&u,&k);
		int tmp;
		for (int j = 0; j < k; ++j){
			scanf("%d", &tmp);
			v[u].push_back(tmp);
		}
	}
	v[0].push_back(1);
	dfs(0);
	++t;
	for (int i = 1; i <= n; ++i){
		if (d[i] == 0) dfs(i);
	}
	
	for (int i = 1; i <= n; ++i){
		cout << i << ' ' << d[i] << ' ' << f[i]+1 << '\n';
	}
}

C++: #include <stdio.h>
 #define GRAY 1
#define WHITE 0
#define BLACK 2
 
int de[101], f[101], col[101];
int A[101][101];
int n, time;
 
void visit(int u) {
  int v;
   col[u] = GRAY;
   de[u] = ++time;
 
  for (v = 1; v <= n; v++) {
    if (col[v] == WHITE && A[u][v] == 1) visit(v);
  }
  col[u] = BLACK;
  f[u] = ++time;
}
 
void dfs() {
  int u;
  for (u = 1; u <= n; u++) {
    col[u] = WHITE;
  }
  time = 0;
  for (u = 1; u <= n; u++) {
    if (col[u] == WHITE) {
      visit(u);
    }
  }
}
 
int main() {
  int i, j, u, k, v;
 
  scanf("%d\n", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d %d", &u, &k);
    for (j = 1; j <= k; j++) {
      scanf("%d ", &v);
      A[u][v] = 1;
    }
  }
 
  dfs();
  for (i = 1; i <= n; i++) {
    printf("%d %d %d\n", i, de[i], f[i]);
  }
 
 
  return 0;
}

C++: #include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

vector<bool> seen;
vector<int> first_order;
vector<int> last_order;

void dfs(const vector<vector<int>> &G, int v, int& count)
{
first_order[v]=count+1;
count++;
seen[v]=true;
for(auto next_v : G[v])
{
if(seen[next_v])continue;
dfs(G, next_v, count);
}
last_order[v]=count+1;
count++;
}

int main()
{
int n,u,k;scanf("%d", &n);
vector<vector<int>> G(n);
for(int i=0;i<n;i++)
{
scanf("%d %d", &u, &k);
for(int i=0;i<k;i++){int v;scanf("%d", &v);G[u-1].push_back(v-1);}
}
seen.assign(n,false);
first_order.resize(n);
last_order.resize(n);
int count=0;
for(int i=0;i<n;i++){if(seen[i])continue;dfs(G, i, count);}
for(int i=0;i<n;i++){printf("%d %d %d\n", i+1, first_order[i], last_order[i]);}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int matrix[110][110];
int d[110];
int f[110];
int n;
int elapsed = 1;

void visit(int v) {
  d[v] = elapsed++;

  FOR(i, 1, n + 1) {
    if (matrix[v][i] && d[i] < 0 ) {
      visit(i);
    }
  }
  f[v] = elapsed++;
}

int main() {
  REP(x, 110) {
    REP(y, 110) {
      matrix[x][y] = 0;
    }
    d[x] = -1;
    f[x] = -1;
  }

  // int n;
  cin >> n;

  REP(_, n) {
    int v, num;
    cin >> v >> num;

    REP(i, num) {
      int cv;
      cin >> cv;
      matrix[v][cv] = 1;
    }
  }


  visit(1);

  FOR(v, 1, n + 1) {
    cout << v << " " << d[v] << " " << f[v] << endl;
  }


  return 0;
}

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

class node {
public:
	int d = -1, f = -1, k, v[100];
};

int cnt = 1;
node V[101];

void Serch(int u) {
	V[u].d = cnt; cnt++;

	for (int i = 0; i < V[u].k; i++) {
		if (V[V[u].v[i]].d < 0) {
			Serch(V[u].v[i]);
		}
	}

	V[u].f = cnt; cnt++;
}

int main() {
	int n, u;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u; cin >> V[u].k;
		for (int j = 0; j < V[u].k; j++) {
			cin >> V[u].v[j];
		}
	}

	for (int i = 1; i <= n; i++) {
		if (V[i].d < 0) Serch(i);
	}

	for (int i = 1; i <= n; i++) cout << i << " " << V[i].d << " " << V[i].f << endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
const int MAX = 100;
int n, G[MAX + 1][MAX + 1] = { 0 };
int tt, d[MAX + 1], f[MAX + 1];
bool book[MAX + 1] = { false };
void dfs_visit(int u)
{
	for (int v = 1; v <= n; v++)
		if (G[u][v] && !book[v])
		{
			d[v] = ++tt;
			book[v] = true;
			dfs_visit(v);
		}
	f[u] = ++tt;
}
void dfs()
{
	for(int i=1;i<=n;i++)
		if (!book[i])
		{
			d[i] = ++tt;
			book[i] = true;
			dfs_visit(i);
		}
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int u, d;
		cin >> u >> d;
		for (int j = 1; j <= d; j++)
		{
			int v;
			cin >> v;
			G[u][v] = 1;
		}
	}
	dfs();
	for (int i = 1; i <= n; i++)
		cout << i << " " << d[i] <<" "<<f[i] << endl;
}