Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<vector<int>> to(n);
   rep(i, 0, n) {
      int u, k;
      cin >> u >> k;
      u--;
      rep(j, 0, k) {
         int v;
         cin >> v;
         v--;
         to[u].push_back(v);
      }
   }
   vector<int> d(n), f(n), color(n);
   int t = 0;
   function<void(int)> dfs = [&](int u) {
      if (color[u] != 0) return;
      color[u] = 1;
      d[u] = ++t;
      for (int i = 0; i < to[u].size(); i++) {
         if (color[to[u][i]] == 0) {
            dfs(to[u][i]);
         }
      }
      color[u] = 2;
      f[u] = ++t;
   };
   rep(i, 0, n) dfs(i);
   rep(i, 0, n) printf("%d %d %d\n", i + 1, d[i], f[i]);
   return 0;
}

C++: #include <iostream>

#define N_MAX 100

using namespace std;

int t = 1;
int adj_matrix[N_MAX][N_MAX];
int d[N_MAX];
int f[N_MAX];

void dfs(int v, int n)
{
    if (d[v] == 0) {
        d[v] = t;
        t++;
    }
    for (int i = 0; i < n; i++) {
        if (adj_matrix[v][i] != 0) {
            dfs(i, n);
        }
    }
    if (f[v] == 0) {
        f[v] = t;
        t++;
    }
}

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

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

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

    dfs(0, n);

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

    return 0;
}

C++: #include <iostream>

using namespace std;

int n;
int A[110][110];
int d[110];
int f[110];
string color[110];
int t = 0;

void dfs_visit(int u) {
  color[u] = "GRAY";
  d[u] = ++t;
  for (int v = 0; v < n; v++) {
    if (A[u][v] == 1 && color[v] == "WHITE") {
      dfs_visit(v);
    }
  }
  color[u] = "BLACK";
  f[u] = ++t;
}

void dfs() {
  // color 初期化
  for (int i = 0; i < n; i++) {
    color[i] = "WHITE";
  }
  for (int u = 0; u < n; u++) {
    if (color[u] == "WHITE") {
      dfs_visit(u);
    }
  }
}

int main() {
    cin >> n;
    int u, k, v;
    for (int i = 0; i < n; i++) {
      cin >> u >> k;
      for (int j = 0; j < k; j++) {
        cin >> v;
        A[u-1][v-1] = 1;
      }
    }
    dfs();

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

C++: ///
// File:  alds1_11_b.cpp
// Author: ymiyamoto
//
// Created on Wed Oct 18 00:19:44 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

static uint32_t n;
static uint32_t graph[100][100];
static uint32_t count = 0;
static uint32_t d[100];
static uint32_t f[100];

static void dfs(uint32_t index)
{
  count++;
  d[index] = count;
  for (uint32_t i = 0; i < n; i++) {
    if (d[i] == 0 && graph[index][i] == 1) {
      dfs(i);
    }
  }
  count++;
  f[index] = count;
}

int32_t main()
{
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    uint32_t id, k;
    cin >> id >> k;
    for (uint32_t j = 0; j < k; j++) {
      uint32_t v;
      cin >> v;
      graph[id - 1][v - 1] = 1;
    }
  }

  for (uint32_t i = 0; i < n; i++) {
    if (d[i] == 0) {
      dfs(i);
    }
  }

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

  return 0;
}

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

using namespace std;

vector<vector<int>> adjacent;
vector<pair<int, int>> ans;
vector<bool>checked;

//?????????is????????????
int dfs(int now,int time) {
	ans[now].first = time;
	checked[now] = true;
	for (int i = 0; i < adjacent[now].size(); i++) 
		if (!checked[adjacent[now][i]]) time = dfs(adjacent[now][i], time + 1);
	ans[now].second = time+1;
	return time + 1;
}

int main() {
	int n,u,k,v;
	cin >> n;
	adjacent = vector<vector<int>>(n);
	checked = vector<bool>(n, false);
	ans.resize(n);

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) cin >> v,adjacent[u - 1].push_back(v-1);
	}
	int time = 1;
	for (int i = 0; i < n; i++) if (!checked[i])time = dfs(i, time)+1;
	for (int i = 0; i < n; i++) 
		cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
}

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;
int dfs(int n,int x,vector<int> k,vector<vector<int>> v,vector<int> &a,vector<int> &b,int &count);


int main(){
	int n;
	cin>>n;
	vector<vector<int> > v(n);
	vector<int> k(n);
	int x;
	rep(i,n){
		cin>>x;
		cin>>k[i];
		v[i].resize(k[i]);
		rep(j,k[i]){
			cin>>v[i][j];
			v[i][j]--;
		}
	}
	vector<int> a(n),b(n);
	int count=1;
	a[0]=1;
	dfs(n,0,k,v,a,b,count);

	rep(i,n){
		if(a[i]==0){
			count++;
			a[i]=count;
			dfs(n,i,k,v,a,b,count);
		}
	}


	rep(i,n){
		cout<<i+1<<" "<<a[i]<<" "<<b[i]<<endl;
	}

	return 0;
}
int dfs(int n,int x,vector<int> k,vector<vector<int>> v,vector<int> &a,vector<int> &b,int &count){
	/*if(k[x]==0){
		count++;
		a[x]=count;
	}*/
	rep(i,k[x]){
		if(a[v[x][i]]==0){
			count++;
			a[v[x][i]]=count;
			dfs(n,v[x][i],k,v,a,b,count);
		}
		if(i==k[x]-1){
			k[x]=0;
		}
	}
	if(k[x]==0){
		count++;
		b[x]=count;
	}
	return 0;
}