Go: package main

/*
深さ優先探索
*/

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

func main() {
	scanner := makeScanner(8192)
	n := eGetInt(scanner)
	g := make([][]int, n+1)
	for i := 1; i < n+1; i++ {
		ints := eGetInts(scanner)
		num, vcount := ints[0], ints[1]
		g[i] = make([]int, vcount)
		for j := 0; j < vcount; j++ {
			g[num][j] = ints[j+2]
		}
	}
	hist := make([]struct{ d, f int }, n+1)
	t := 0
	var visit func(int)
	visit = func(num int) {
		if hist[num].d == 0 {
			stack := []int{}
			t++
			hist[num].d = t
			stack = append(stack, num)
			for len(stack) > 0 {
				// トップを訪問する
				top := stack[len(stack)-1]
				for i := 0; i < len(g[top]); i++ {
					if hist[g[top][i]].d == 0 {
						t++
						hist[g[top][i]].d = t
						stack = append(stack, g[top][i])
						goto endloop
					}
				}
				// 訪問場所がなくなったら
				// pop
				stack = stack[0 : len(stack)-1]
				t++
				hist[top].f = t
			endloop:
			}
		}
	}
	for i := 1; i < n+1; i++ {
		visit(i)
	}
	for i := 1; i < n+1; i++ {
		fmt.Println(i, hist[i].d, hist[i].f)
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
bool G[110][110];
int d[110], f[110], timer;
bool seen[110];

void dfs(int now){
    d[now] = timer;

    seen[now] = true;

    for(int to=1; to<=n; ++to){
        if(G[now][to] == true && seen[to] == false){
            ++timer;
            dfs(to);
        }
    }

    ++timer;
    f[now] = timer;

}

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

    timer = 0;
    for(int i=1; i<=n; ++i){
        if(seen[i] == false){
            ++timer;
            dfs(i);
        }
    }

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

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

int t=1;
int n;
int d[101],f[101];
int v[101];
vector<int> edges[101];

void dfs(int cur)
{
    if(d[cur]==-1)
    {
        d[cur]=t;
        v[cur]=1;
        t+=1;
    }
    int dst;
    for(dst=1;dst<=n;dst++)
    {
        int flag=0;
        for(int i=0;i<edges[cur].size();i++)
        {
            if(edges[cur][i]==dst)
				{
					flag=1;
					break;
				}
        }
        if(v[dst]==-1&&flag)
		  dfs(dst);
    }
    if(f[cur]==-1)
    {
        f[cur]=t;
        t+=1;
    }
}

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int u,k,y;
		cin >> u >> k;
		for(int j=0;j<k;j++)
        {
            cin >> y;
            edges[u].push_back(y);
        }
	}
	for(int i=1;i<=n;i++)
	{
        d[i]=-1;
        f[i]=-1;
        v[i]=-1;
    }
	for(int dst=1;dst<=n;dst++)
        dfs(dst);
	for(int i=1;i<=n;i++)
	   cout << i << ' ' << d[i] <<  ' ' <<  f[i] <<  endl;
}

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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
vi d, f;
vvi G;
int t = 0;

void dfs(int n)
{
    t++;
    d[n] = t;
    for(int i : G[n]) if(d[i] == 0) dfs(i);
    t++;
    f[n] = t;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> n;
    G.resize(n+1);
    d.resize(n+1, 0);
    f.resize(n+1, 0);
    REP(i, n)
    {
        int u, k; cin >> u >> k;
        REP(j, k)
        {
            int v; cin >> v;
            G[u].pb(v);
        }
    }

    REPS(i, n)
    {
        if(d[i] == 0) dfs(i);
    }

    REPS(i, n) cout << i << " " << d[i] << " " << f[i] << endl;
}

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

class vertex{
public:
  vector<vertex*> to;
  bool visited;
  int num;
  int visit_time;
  int leave_time;
  vertex(){
    visited=false;
  }
  void dfs(){
    visited=true;
    visit_time=time();
    for(int i=0; i<to.size(); i++){
      if(!to[i]->visited) to[i]->dfs();
    }
    leave_time=time();
  }

  void print(){
    cout << num << " " << visit_time << " " << leave_time << endl;
  }

private:
  static int time(){
    static int ti=0;
    ti++;
    return ti;
  }
};

int main(){
  int n; cin >> n;
  vertex graph[n+1];

  int v, k, to;
  for(int i=0; i<n; i++){
    cin >> v >> k;
    graph[v].num = v;
    for(int j=0; j<k; j++){
      cin >> to;
      graph[v].to.push_back(&graph[to]);
    }
  }


  for(int v=1; v<=n; v++){
    if(!graph[v].visited) graph[v].dfs();
  }

  for(int v=1; v<=n; v++){
    graph[v].print();
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

using Graph = vector<vector<int>>;

vector<bool> seen;
vector<int> first_order;
vector<int> last_order;

void dfs(const Graph &G, int v, int& ptr){
  first_order[v] = ptr++;

  seen[v] = true;
  for(int nv : G[v]){
    if(seen[nv] == true) continue;
    dfs(G, nv, ptr);
  }

  last_order[v] = ptr++;
}

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

  Graph G(n+1);
  rep(i, n){
    int u, k; cin >> u >> k;
    rep(j, k){
      int v; cin >> v;
      G[u].push_back(v);
    }
  }

  seen.assign(n+1, false);
  first_order.resize(n+1);
  last_order.resize(n+1);
  int ptr = 1;
  REP(i, 1, n){
    if(seen[i] == false){
      dfs(G, i, ptr);
    }
  }

  REP(i, 1, n){
    printf("%d %d %d\n", i, first_order[i], last_order[i]);
  }

  return 0;
}