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>

using namespace std;

const int N = 105;

int n, k, u, v, clok;
int d[N], f[N], mark[N];
vector<int> a[N];

void DFS(int p)
{
  mark[p] = 1;
  d[p] = clok;
  clok++;
  for(int i = 0; i < a[p].size(); i++)
    if(!mark[a[p][i]]){
      DFS(a[p][i]);
    }
  f[p] = clok;
  clok++;
}

int main()
{
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> u >> k;
    for(int j = 1; j <= k; j++) {
      cin >> v;
      a[u].push_back(v);
    }
    sort(a[u].begin(), a[u].end());
  }
  clok = 1;
  for(int i = 1; i <= n; i++)
    if(!mark[i]) DFS(i);
  for(int i = 1; i <= n; i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;
const int INF = 1e18;

struct edge
{
    int to;
    int cost;
};
using Graph = vector<vector<edge>>;

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

int n;
Graph G;

int seen[110];
int discover[110];
int finish[110];
int stamp = 0;

void dfs(int cur)
{
    discover[cur] = stamp++;

    seen[cur] = BLACK;
    for (auto ne : G[cur])
    {
        int v = ne.to;
        int vc = ne.cost;
        if (seen[v] == BLACK)
            continue;
        dfs(v);
    }

    finish[cur] = stamp++;
}

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    G.resize(n + 1);

    for (int i = 0; i <= n; i++)
    {
        if (i == 0)
        {
            for (int j = 1; j <= n; j++)
            {
                G[0].push_back((edge){j, 1});
            }
        }
        else
        {
            int u, k;
            cin >> u >> k;
            for (int j = 0; j < k; j++)
            {
                int v;
                cin >> v;
                G[u].push_back((edge){v, 1});
            }
        }
    }

    for (int i = 0; i < 110; i++)
    {
        seen[i] = WHITE;
        discover[i] = INF;
        finish[i] = INF;
    }

    dfs(0);

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

signed main()
{
    solve();
    return 0;
}

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

int n, t;
int v[100][100];
int d[100], f[100];

void stamp(int id) {
//	if (t > 2 * n)
//		return;
	
	if (d[id - 1] == 0) {
		d[id - 1] = t;
		t++;
		int i = 0;
		while (v[id - 1][i] == 0)
			i++;
		if (i < n && d[i] == 0)
			stamp(i + 1);
		else
			stamp(id);
	}
	else if (f[id - 1] == 0) {
		int i;
		for(i = n - 1; i > -1; i--)
			if (v[id - 1][i] == 1 && d[i] == 0)
				stamp(i + 1);
		if (i < 0 && f[id - 1] == 0) {
			f[id - 1] = t;
			t++;
			for (i = n - 1; i > -1; i--)
				if (v[i][id - 1] == 1 && f[i] == 0)
					stamp(i + 1);
		}
	}
	else
		return;
}

int main()
{
	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++)
			v[i][j] = 0;

	for (int i = 0; i < n; i++) {
		int u, k, s;

		cin >> u >> k;

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

	t = 1;
	stamp(1);

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

	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>

using namespace std;

int common_time=1,n;

int table[101][101],time_table[101][2];

void func(int node){
	if(time_table[node][0] == 0){
		time_table[node][0] = common_time++;
	}else{
		return;
	}
	for(int i=1;i<=n;i++){
		if(table[node][i] == 1){
			func(i);
		}
	}
	time_table[node][1] = common_time++;
}

int main(){
	int row,num,col;
	scanf("%d",&n);

	for(int i=1;i<=n;i++){
		for(int k=1;k<=n;k++){
			table[i][k]=0;
		}
		time_table[i][0]=0;
		time_table[i][1]=0;
	}

	for(int i=1;i<=n;i++){
		scanf("%d %d",&row,&num);
		for(int k=1;k<=num;k++){
			scanf("%d",&col);
			table[row][col]=1;
		}
	}

	for(int i=1;i<=n;i++){
		func(i);
	}

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

    return 0;
}

C++: #include <iostream>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

using namespace std;

int n, t = 0;
int color[MAX+1];
int m[MAX+1][MAX+1];
int d[MAX+1], f[MAX+1];

void visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++t;
    for(v = 1; v <= n; v++){
        if(m[u][v] == 0) continue;
        if(color[v] == WHITE) visit(v);
    }
    color[u] = BLACK;
    f[u] = ++t;
}

void dfs(){
    int u, i;
    for(u = 1; u <= n; u++) color[u] = WHITE;
    for(u = 1; u <= n; u++){
        if(color[u] == WHITE) visit(u);
    }
}

int main(){
    int k, u, v, i, j;
    
    cin >> n;

    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++) m[i][j] = 0;
    }

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

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

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

using namespace std;

vector<int> adja[101];
int d[101], f[101], cnt;

void dfs(int u) {
    d[u] = ++cnt;
    for (auto v : adja[u]) {
        if (d[v] > 0)
            continue;
        dfs(v);
    }
    f[u] = ++cnt;
}

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

    return 0;
}