Go: package main

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

const MAX = 101

var f [MAX]int
var d [MAX]int
var list [][]int
var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func dfs(u, cnt int) int {
	if d[u] != 0 {
		return cnt
	}

	cnt++
	d[u] = cnt
	for _, next := range list[u] {
		cnt = dfs(next, cnt)
	}
	cnt++
	f[u] = cnt
	return cnt
}

func main() {
	n := scanInt()
	list = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			n := scanInt()
			list[u] = append(list[u], n)
		}
	}

	cnt := 0
	for i := 1; i <= n; i++ {
		cnt = dfs(i, cnt)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, d[i])
		fmt.Fprint(w, " ")
		fmt.Fprint(w, f[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

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

using namespace std;

enum COLOR {
  WHITE,
  GRAY,
  BLACK,
};

static const int NIL = -1;
static const int N = 100;

static int M[N][N] = {};

static inline int next(int u, int n, int next_array[]) {
  for (int v = next_array[u]; v < n; v++) {
    next_array[u] = v + 1;
    if (M[u][v]) {
      return v;
    }
  }
  return NIL;
}

static vector<int> u(N, 0);
static vector<COLOR> color(N, WHITE);
static int total_time = 0;
static vector<int> visit_time(N, 0), finish_time(N, 0);

static void dfs_visit(int r, int n) {
  vector<int> next_array(N, 0);

  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  visit_time[r] = ++total_time;

  while (!S.empty()) {
    int u = S.top();
    int v = next(u, n, &next_array[0]);
    if (v != NIL) {
      if (color[v] == WHITE) {
        color[v] = GRAY;
        visit_time[v] = ++total_time;
        S.push(v);
      }
    } else {
      S.pop();
      color[u] = BLACK;
      finish_time[u] = ++total_time;
    }
  }
}

void dfs(int n) {
  for (int u = 0; u < n; u++) {
    if (color[u] == WHITE) {
      dfs_visit(u, n);
    }
  }
  
  for (int i = 0; i < n; i++) {
    cout << i + 1 << " " << visit_time[i] << " " << finish_time[i] << endl;
  }
}

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

  int number, count, value;
  for (int i = 0; i < n; i++) {
    cin >> number >> count;
    number--;
    for (int j = 0; j < count; j++) {
     cin >> value;
     value--;
     M[number][value] = 1; 
    }
  }
  
  dfs(n);

  return 0;
}

C++: /*
 * ALDS1_11_B.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<iostream>
#include<vector>

using namespace std;

int d[101];
int f[101];
int time;

void dfsRec(vector<int>* a, int n, int v) {
	if(d[v] > 0) return;
	time++;
	d[v] = time;
	for(int &x:a[v]) {
		dfsRec(a, n, x);
	}
	time++;
	f[v] = time;
}

int main() {
	int n;
	vector<int> adj[101];

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

	dfsRec(adj, n, 1);

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

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;
}