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++: #include <cstdio>
#include <vector>

using namespace std;

#define MAX_N (105)

vector<int> G[MAX_N];
bool arrived[MAX_N];
int d[MAX_N];
int f[MAX_N];
int n;
int t;
void dfs( int cur ) {
    t++;
    d[cur] = t;

    for ( int i = 0; i < G[cur].size(); i++ ) {
	int next = G[cur][i];
	if ( !arrived[next] ) {
	    arrived[next] = true;
	    dfs( next );
	}
    }

    t++;
    f[cur] = t;

    return;
}

int main()
{
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);
	u--;
	for ( int j = 0; j < k; j++ ) {
	    int v;
	    scanf("%d", &v);
	    v--;
	    G[u].push_back(v);
	}
    }

    t = 0;
    for ( int i = 0; i < n; i++ ) {
	if ( !arrived[i] ) {
	    arrived[i] = true;
	    dfs(i);
	}
    }


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

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
#include <list>
using namespace std;

int n;

struct Node{
public:
  int id, d, f, flag;
  vector<int> c;
  Node(){d = 1000000007;f = flag = 0;}
};

vector<Node> v(101);

void rec(int id, int &t){
  if(v[id].flag)return;
  else          v[id].flag = 1;
  v[id].d = min(v[id].d, ++t);
  for(int i=0;i<v[id].c.size();i++) {
    rec(v[id].c[i], t);
  }
  v[id].f = max(v[id].f, ++t);
}


bool asc(const Node &right, const Node &left){return right.id < left.id;}

int main(){
  cin >> n;
  
  v[0].id = 0;  
  for(int i=1;i<=n;i++){
    int t, a;  cin >> a >> t;
    vector<int> b(t);
    for(int j=0;j<t;j++){
      int val;cin >> val;
      b[j] = val;
    }
    v[a].id = a;
    v[a].c = b;
  }
  sort(v.begin(), v.end(), asc);

  int ti = 0;
  for(int i=1;i<=n;i++){
    rec(i, ti);
  }

  for(int i=1;i<=n;i++){
    printf("%d %d %d\n", v[i].id, v[i].d, v[i].f);
  }
  return 0;
}

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

using namespace std;
struct node {
    node() {};
    node(int i, int n, int* xs) : id {i}, ns {vector<int>(xs, xs+n)} {
        delete xs;
    };
    int id;
    vector<int> ns;
    int in_time;
    int out_time;
};

int dfs(map<int, node*> graph, int time, int id){
    node* n = graph[id];
    if(n->in_time > 0){
        return time;
    }
    n->in_time = ++time;
    vector<int> ns = n->ns;
    for(auto it = ns.begin(); it != ns.end(); ++it){
        time = dfs(graph, time, *it);
    }
    n->out_time = ++time;
    return time;
}

int main(){
    int n;
    cin >> n;
    map<int, node*> graph {};
    int st = 1000000000;
    for(int i = 0; i < n; ++i){
        int id;
        cin >> id;
        st = min(st, id);
        int k;
        cin >> k;
        int* ns = new int[k];
        for(int j = 0; j < k; ++j){
            cin >> ns[j];
        }
        graph[id] = new node(id, k, ns);
    }
    for(auto it = graph.begin(); it != graph.end(); ++it){
        pair<int, node*> p = *it;
        if(p.second->in_time){
            continue;
        }
        dfs(graph, 0, p.first);
    }
    for(auto it = graph.begin(); it != graph.end(); ++it){
        pair<int, node*> p = *it;
        cout << p.first << ' ' << p.second->in_time << ' ' << p.second->out_time << endl;
    }
}

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

int n, t = 0;
int A[101][101];
int d[101], f[101];

void dfs(int r) {
	d[r] = ++t;
	for (int i = 1; i <= n; i++) {
		if (A[r][i] == 1 && d[i] == 0) dfs(i);
	}
	f[r] = ++t;
	return;
}

int main() {
	int u, v, l;
	cin >> n;

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

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			A[i][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++) {
		cin >> u >> l;
		for (int j = 0; j < l; j++) {
			cin >> v;
			A[u][v] = 1;
		}
	}

	dfs(1);

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

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#define Lens 105
using namespace std;
int N;
int A[Lens][Lens];
int S[Lens], E[Lens];
int sum = 0;
char c[Lens];

void dns(int i)
{
	sum++;
	S[i] = sum;
	c[i] = 'g';
	for (int j = 1; j <= N; j++)
	{
		if (A[i][j] == 1 && c[j] == 'w')
			dns(j);
	}
	sum++;
	E[i] = sum;
	c[i] = 'b';
}

int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		int k, n;
		cin >> k >> n;
		c[i] = 'w';
		for (int i = 0; i < n; i++)
		{
			int j;
			cin >> j;
			A[k][j] = 1;
		}
	}
	/*
	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= N; j++)
		{
			if (j > 1)
				cout << ' ';
			cout << A[i][j];
		}
		cout << endl;
	}
	*/
	dns(1);
	for (int i = 1; i <= N; i++)
	{
		cout << i << ' ' << S[i] << ' ' << E[i] << endl;
	}
	return 0;
}