Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include <iostream>
#include <stack>
using namespace std;
const int MAX_N = 100;

int A[MAX_N+1][MAX_N+1];
pair<int, int> TIMESTAMPS[MAX_N+1];
int N;

void solve() {
  int ts = 0;
  stack<int> S;

  for (int i = N; i > 0; i--) {
    if (TIMESTAMPS[i].first == 0) S.push(i);
  }

  while (!S.empty()) {
    int c = S.top();

    if (TIMESTAMPS[c].first == 0)
      TIMESTAMPS[c].first = ++ts;

    for (int i = N; i > 0; i--) {
      if (A[c][i] == 1 && TIMESTAMPS[i].first == 0)
        S.push(i);
    }

    if (S.top() == c) {
      if (TIMESTAMPS[c].second == 0)
        TIMESTAMPS[c].second = ++ts;
      S.pop();
    }
  }
}

int main() {
  cin >> N;

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

    }
    TIMESTAMPS[i] = make_pair(0, 0);
  }

  for (int i = 0; i < N; i++) {
    int u, k; cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int t; cin >> t;
      A[u][t] = 1;
    }
  }

  solve();

  for (int i = 1; i <= N; i++) {
    cout << i << ' '
         << TIMESTAMPS[i].first << ' '
         << TIMESTAMPS[i].second << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int n;
vector<vector<int>> graph(100);
vector<int> d(100, 0), f(100);
int t = 0;

void DFS(int u) {
    if (d[u] != 0) return;
    ++t;
    d[u] = t;
    for (int v : graph[u]) DFS(v);
    ++t;
    f[u] = t;
    return;
}

int main() {
    cin >> n;
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        rep(j, k) {
            int v;
            cin >> v;
            graph[u - 1].push_back(v - 1);
        }
    }
    
    rep(i, n) DFS(i);
    rep(i, n) cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    return 0;
}

C++: /* ALDS1_11_B: Depth First Search */

#include <iostream>
#include <cstdio>
#include <vector>
using std::vector;

vector<int> *graph;
int elapsed = 1;

// Search the graph recursively by depth-first search.
void traverse(int id, int found[], int finished[]) {
    if (0 < found[id]) {
        return;
    }

    found[id] = elapsed++;
    vector<int> degrees = graph[id];
    for (int i = 0; i < degrees.size(); i++) {
        traverse(degrees[i], found, finished);
    }
    finished[id] = elapsed++;
}

int main() {
    int n_v;
    scanf("%d", &n_v);

    int max_v = n_v + 1;
    graph = new vector<int>[max_v];

    for (int i = 0; i < max_v; i++) {
        int id, n_degrees;
        scanf("%d %d", &id, &n_degrees);

        for (int j = 0; j < n_degrees; j++) {
            int deg_id;
            scanf("%d", &deg_id);
            graph[id].push_back(deg_id);
        }
    }

    int found[max_v];
    int finished[max_v];
    std::fill_n(found, max_v, 0);
    std::fill_n(finished, max_v, 0);

    for (int id = 1; id < max_v; id++) {
        traverse(id, found, finished);
    }

    for (int id = 1; id < max_v; id++) {
        printf("%d %d %d\n", id, found[id], finished[id]);
    }
    return 0;
}

C++: #include <utility>
#include <algorithm>
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector <int> m[103];
int kakunin[103]={0};
int d[103];
int f[103];
int cnt=0;
void dfs(int num){
    d[num]=cnt++;
    for(int i=0;i<m[num].size();i++){
        if(kakunin[m[num][i]]==0){kakunin[m[num][i]]=1;dfs(m[num][i]);}}
    f[num]=cnt++;
}
int main() {
    int n,a,tmp,id;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>id;
        cin>>a;
        for(int j=0;j<a;j++){
            scanf("%d",&tmp);
            m[id].push_back(tmp);
        }
    }
    for(int i=0;i<102;i++){m[0].push_back(i);}
    dfs(0);
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<d[i]-1<<" "<<f[i]-1;}
}

C++: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

vector<int> g[100];
vector<bool> visit(100);
vector<int> d(100), f(100);

int cnt = 0;

void dfs(int v) {
  d[v] = ++cnt;
  visit[v] = true;
  for (auto u : g[v]) {
    if (!visit[u]) {
      dfs(u);
    }
  }
  f[v] = ++cnt;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int u, k;
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; ++j) {
      int v;
      cin >> v;
      v--;
      g[u].push_back(v);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (!visit[i]) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << i + 1 << " " << d[i] << " " << f[i] << endl;
  }
  return 0;
}

C++: #include<stdio.h>

#define WHITE 0   // not visited yet.
#define GRAY 1    // visited, but not completed.
#define BLACK 2   // search completed.

int G[101][101];        // adjacency list.
int color[101];         // visited/completed sign.
int n;                  // size.
int d[101], f[101], t;  // first visit time/complete time.

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

    for(next = 1; next <= n; next++){
        if(i == next && G[i][i] > 0) break;   // if self-looped, through.
        if(G[i][next] > 0 && color[next] == WHITE){  // if not visited yet, visit.
            search_loop(next);
        }
    }
    f[i] = ++t;
    color[i] = BLACK;  // completed. 

    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++) printf("%d %d %d", i, d[i], f[i]);

    return ;
}

int main()
{
    int i, j, k, e;
    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++){ G[i][j] = 0; } }

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

    dfs();
    return 0;
}