Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

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

int n, G[MAX][MAX], d[MAX], f[MAX], Mytime, st[MAX];

void dfs(int r) {
	if (st[r] != 0) return;
	int nt[n + 1], i;
	for (i = 1; i <= n; i++) {
		nt[i] = 1;
	}
	stack<int> S;
	S.push(r);
	d[r] = ++Mytime;
	st[r] = 1;
	while (!S.empty()) {
		int u = S.top();
		int v;
		for (v = nt[u]; v <= n; v++) {
			nt[u] = v + 1;
			if (G[u][v] && st[v] == 0) 
				break;
		}
		if (v <= n) {
			d[v] = ++Mytime;
			st[v] = 1;
			S.push(v);
		} else {
			S.pop();
			f[u] = ++Mytime;
		}
	}
}

int main(void) {
	int i, j, u, k, v;
	for (i = 0; i < MAX; i++) {
		d[i] = 0;
		f[i] = 0;
		st[i] = 0;
		for (j = 0; j < MAX; j++) {
			G[i][j] = 0;
		}
	}
	Mytime = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		for (j = 0; j < k; j++) {
			cin >> v;
			G[u][v] = 1;
		}
	}
	for (i = 1; i <= n; i++) {
		dfs(i);
	}
	dfs(1);
	for (i = 1; i <= n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
}

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

const int MAXINT = 10000;

// typedef std::vector<std::vector<int> > mat_int;
// typedef std::vector<std::vector<bool> > mat_bool;

void dfs(std::vector<std::vector<int> >& adj_list, std::vector<int>& d, std::vector<int>& f, int& time, int root = 0 ){
  if(d[root] > time){
    d[root] = time;
    for(int const& v: adj_list[root]){
      time++;
      dfs(adj_list, d, f, time, v);
    }
    time++;
    f[root] = time;
  }

}


int main(int argc, char const *argv[]) {
  int n; // .. 100
  std::cin >> n;
  // mat_bool adj(n, std::vector<bool>(n));
  // mat_int d(n, std::vector<int>(n)), f(n, std::vector<int>(n));
  std::vector<std::vector<int> > adj_list(n);
  std::vector<int> d(n, MAXINT), f(n, MAXINT);

  for(int q=0; q<n; ++q){
    int i_plus_1, k;
    std::cin >> i_plus_1;
    std::cin >> k;
    for(int p=0; p<k; ++p){
      int j_plus_1;
      std::cin >> j_plus_1;
      // adj[i_plus_1-1][j_plus_1-1] = true;
      adj_list[i_plus_1 - 1].push_back(j_plus_1-1);
    }
  }

  int t = 1;
  dfs(adj_list, d, f, t);

  for(int i=0; i<n; ++i){
    std::cout << (i+1)
      << " " << d[i]
      << " " << f[i]
      << std::endl;

  }


  // for(auto it = adj_list.begin(); it != adj_list.end(); ++it){
  //   std::cout << ": ";
  //   for(auto jt = (*it).begin(); jt != (*it).end(); ++jt){
  //     std::cout << (*jt) << ' ';
  //   }
  //   std::cout << std::endl;
  // }

  return 0;
}

C++: #include<stdio.h>
#define MAX 101

int G[MAX][MAX], d[MAX], f[MAX];

void adjacency_matrices(int n) {
    int i, j, u, m, k;

    for (i=1; i<=n; i++) {
        scanf("%d", &u);
        scanf("%d", &m);
        for (j=1; j<=m; j++) {
            scanf("%d", &k);
            G[u][k] = 1;
        }
    }
}

int depth_first_search(int t, int i, int n) {
    int j;
    bool get;
    d[i] = t;

    for (j=1; j<=n; j++) {
        if (G[i][j]==1 && d[j]==-1) {
            t = depth_first_search(++t, j, n);
        } 
    }

    f[i] = ++t;

    return t;
}

int main() {
    int n, i, j, t;
    t = 0; 

    scanf("%d", &n);
    for (i=1; i<=n; i++) {
        d[i]=f[i]=-1;
        for (j=1; j<=n; j++) {
            G[i][j] = 0;
        }
    }

    adjacency_matrices(n);

    for (i=1; i<=n; i++) {
        if (f[i]==-1) {
            t = depth_first_search(++t, i, n);
        }
    }

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

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

static const int N = 100;
int n, m[N][N];
int time, begT[N], endT[N];
bool visited[N];

int nxt(int u)
{
	for (int v = 0; v < n; ++v)
	{
		if (m[u][v] > 0 && !visited[v]) return v;
	}
	return -1;
}

void dfs_helper(int idx)
{
	stack<int> s;
	s.push(idx);
	begT[idx] = time++;
	visited[idx] = true;

	while (!s.empty())
	{
		int u = s.top();
		int v = nxt(u);
		if (-1 == v)
		{
			s.pop();
			endT[u] = time++;
			continue;
		}
		s.push(v);
		begT[v] = time++;
		visited[v] = true;
	}
}

void dfs()
{
	time = 1;

	for (int i = 0; i < n; ++i)
	{
		if (!visited[i]) dfs_helper(i);
	}

	for (int i = 0; i < n; ++i)
	{
		cout << i + 1 << " " << begT[i] << " " << endT[i] << endl;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i)	{
		for (int j = 0; j < n; ++j)	{
			m[i][j] = 0;
		}
	}

	for (int i = 0; i < n; ++i)
		visited[i] = false;

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

	dfs();

	return 0;
}

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

#define WHITE 0
#define GRAY 1
#define BLACK 2

int G[101][101];
int color[101];
int n;
int d[101], f[101], t;

void search_loop(int i)
{
	int next;
	d[i] = ++t;
	color[i] = GRAY;

	for(next = 1; next <= n; next++){
		if(i == next && G[i][i] > 0) break;
		if(G[i][next] > 0 && color[next] != BLACK){
			search_loop(next);
		}
	}
	f[i] = ++t;
	color[i] = BLACK;

	return;
}

void dfs()
{
	int i;
	for(i = 1; i <= n; i++) color[i] = WHITE;  // initialize.

	t = 0;
	for(i = 1; i <= n; i++){
		if(color[i] == WHITE) search_loop(i);
	}
	for(i = 1; i <= n; i++){
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return ;
}

int main()
{
	int i, j, k, e;
	cin >> n;
	for(i = 1; i <= n; i++){
		for(j = 1; j <= n; j++){
			G[i][j] = 0;
		}
	}
	do{
		cin >> i >> e;
		for(j = 1; j <= e; j++){
			cin >> k;
			G[i][k] = 1;
		}
	}while(i < n);

	dfs();

	return 0;
}

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

using namespace std;

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

  vector<vector<int>> adjacent(n);
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    --u;

    for (int i = 0; i < k; i++) {
      int v;
      cin >> v;
      --v;

      adjacent[u].push_back(v);
    }
  }

  vector<int> d(n, 0), f(n, 0);
  vector<bool> visited(n, false);
  stack<int> S;

  S.push(0);

  int t = 1;

  d[0] = t;

  while (!S.empty()) {
    ++t;

    int u = S.top();

    if (!visited[u]) {
      visited[u] = true;
    }

    bool done = true;
    for (int i = 0; i < adjacent[u].size(); i++) {
      int v = adjacent[u][i];

      if (!visited[v]) {
        done = false;
        d[v] = t;
        S.push(v);
        break;
      }
    }

    if (done) {
      f[u] = t;
      S.pop();
    }

    // スタックが空になった後、未訪問なノードがあればそれを始点として再度DFSする
    if (S.empty()) {
      for (int i = 0; i < n; i++) {
        if (!visited[i]) {
          ++t;
          S.push(i);
          d[i] = t;
          break;
        }
      }
    }
  }

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

  return 0;
}

/*
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0
*/