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<iostream>
using namespace std;

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

int time_stamp;
int M[N+1][N+1];

void dfs(int n, int vertex, int d[], int f[], int color[]) {  
  color[vertex] = GRAY;
  d[vertex] = ++time_stamp;
  for (int i = 1; i <= n; i++) {    
    if (M[vertex][i] && color[i] == WHITE) {
      dfs(n, i, d, f, color);
    }
  }
  color[vertex] = BLACK;
  f[vertex] = ++time_stamp;
}

void search(int n, int d[], int f[], int color[]) {
  // 初期状態
  for (int i = 1; i <= n; i++) color[i] = WHITE;
  time_stamp = 0;
  // dfs
  for (int i = 1; i <= n; i++) {
    if (color[i] == WHITE) {
      dfs(n, i, d, f, color);
    }
  }
}

int main() {
  int i, j, n, u, k, v, d[N+1], f[N+1], color[N+1];
  
  cin >> n;
  // 隣接行列を取得
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      M[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    for (j = 0; j < k; j++) {
      cin >> v;
      M[u][v] = 1;
    }
  }

  search(n, d, f, color);

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

  return 0;
}

C++: #include <cstdio>

typedef struct Node {
    int id;
    int d;
    int f;
    int count;
} Node;


int count(int id, int now, Node *node, int a[101][100]){
    if(node[id].d == 0) node[id].d = now;
    if(node[id].f != 0) return now - 1;
    if(node[id].count == 0){
        node[id].f = now + 1;
        return node[id].f;
    }
    for(int i = 0; i < node[id].count; ++i){
        int nextId = a[id][i];
        now = count(nextId, now + 1, node, a);
    }
    node[id].f = now + 1;
    return node[id].f;
}

int main(){
    int n;
    std::scanf("%d", &n);
    Node node[101];
    int a[101][100];
    for(int i = 1; i <= n; ++i){
        int id;
        std::scanf("%d", &id);
        node[id].id = id;
        std::scanf("%d", &node[id].count);
        for(int j = 0; j < node[id].count; ++j){
            std::scanf("%d", &a[i][j]);
        }
    }
    count(1, 1, node, a);
    for(int i = 1; i <= n; ++i){
        std::printf("%d %d %d\n", node[i].id, node[i].d, node[i].f);
    }

    return 0;
}

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

int time1 = 0;
int a[110][110] = {};
int d[110] = {};
int f[110] = {};
int n;
int p;

void dfs(int cur){
  if(d[cur]==0){
    d[cur] = time1;
  }
  time1 += 1;
  f[cur] = time1;

  for(int dst=1;dst<=n;dst++){
    if(a[cur][dst]==1&&d[dst]==0){
      a[cur][dst]=2;
      dfs(dst);
    }
  }
  for(int k=1;k<=n;k++){
    if(a[k][cur]==2){
      a[k][cur]=1;
      p+=1;
      dfs(k);
    }else{
      p=0;
    }
  }
  if(p==0){
    for(int k=1;k<=n;k++){
      if(d[k]==0){
	time1+=1;
	dfs(k);
      }
    }
  }
}

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

C++: #include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
void func(int);
int n,k[101],v[101][100],d[101],f[101],cnt;
int flg[101];
int main(void)
{
	int i,u,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	{
		scanf("%d %d",&u,&k[i]);
		for(j=0;j<k[i];j++)	scanf("%d",&v[i][j]);
	}
	for(i=1;i<=n;i++)	flg[i]=0;
	cnt=0;
	for(i=1;i<=n;i++)	{
		if(flg[i]==0)		func(i);
	}
	for(i=1;i<=n;i++)	printf("%d %d %d\n",i,d[i],f[i]);
	return 0;
}
void func(int nn)
{
	int i;
	cnt++;	
	d[nn]=cnt;
	flg[nn]=1;
	for(i=0;i<k[nn];i++)	{
		if(flg[v[nn][i]]==0)	{
			func(v[nn][i]);
		}
	}
	cnt++;
	f[nn]=cnt;
}

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

vector<vector<int>> g;
vector<int> s, e;

void dfs(int v, int& t) {
    if (s[v]) return;
    s[v] = t++;
    for (auto& x : g[v]) {
        dfs(x, t);
    }
    e[v] = t++;
}

int main() {
    int n; cin >> n;
    g.resize(n); s.resize(n); e.resize(n);
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k; u--;
        while (k--) {
            int v; cin >> v; v--;
            g[u].push_back(v);
        }
        sort(g[u].begin(), g[u].end());
    }
    int t = 1;
	for (int i = 0; i < n; i++) dfs(i, t);
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << s[i] << " " << e[i] << endl;
    }
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<ll> node;
};

ll N;
Vertex V[105];
pll ans[105];

void dfs(ll idx, ll &time) {
    ans[idx].first = time++;
    for (auto &nxt:V[idx].node) {
        if (ans[nxt].first > 0)
            continue;
        dfs(nxt, time);
    }
    ans[idx].second = time++;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) {
        ll n, k;
        cin >> n >> k;
        n--;
        REP(j, k) {
            ll v;
            cin >> v;
            v--;
            V[n].node.push_back(v);
        }
    }
    REP(i, N) {
        ans[i] = pll(0, 0);
    }
    ll time = 1;
    REP(i, N) {
        if (ans[i].first > 0)
            continue;
        dfs(i, time);
    }
    REP(i, N) {
        cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}