Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

C++: #include<iostream>
#include<vector>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;

int t = 1;
int n;
int a[105][105];

vector<int> d;
vector<int> f;
vector<int> g;
vector<int> color;

void visit(int u){
  color[u] = GRAY;
  d[u] = t++;

  for(int i = 0; i < n; i++){
    if(a[u][i] == 0) continue;
    if(color[i] == WHITE) visit(i);
  }

    color[u] = BLACK;
    f[u] = t++;
}

void dfs(){
  for(int i = 0; i < n; i++) color[i] = WHITE;

  for(int i = 0; i < n; i++){
    if(color[i] == WHITE) visit(i);
  }
}

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

  d.resize(n+5);
  f.resize(n+5);
  g.resize(n+5);
  color.resize(n+5);

  for(int i = 0; i < n; i++){
    cin >> u >> k;
    u--;

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

  dfs();

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

  return 0;

}

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

static const int N = 100;
static const int white = 0;
static const int gray = 1;
static const int black = 2;

int n, m[N][N];
int nt[N], color[N];
int d[N], f[N];
int tt;

int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (m[u][v] == 1)
			return v;
	}
	return -1;
}

void dfs(int u) {
	for (int i = 0; i < n; i++)
		nt[i] = 0;
	stack<int> s;
	s.push(u);
	color[u] = gray;
	d[u] = ++tt;
	while (!s.empty()) {
		int u = s.top();
		int v = next(u);
		if (v != -1) {
			if (color[v] == white) {
				s.push(v);
				color[v] = gray;
				d[v] = ++tt;
			}
		} else {
			s.pop();
			color[u] = black;
			f[u] = ++tt;
		}
	}
}

void dfs_init() {
	tt = 0;
	for (int i = 0; i < n; i++)
		color[i] = white;
	
	for (int i = 0; i < n; i++) {
		if (color[i] == white)
			dfs(i);
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}

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

C++: #include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u)
{
    for (int v = nt[u]; v < n; v++)
    {
        nt[u] = v + 1;
        if (M[u][v] > 0) return v;
    }
    return -1;
}

void dfs_visit(int r)
{
    for (int i = 0; i < n; i++) nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while ( !S.empty() )
    {
        int u = S.top();
        int v = next(u);
        if (v != -1)
        {
            if ( color[v] == WHITE)
            {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }
        else
        {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs()
{
    for (int i = 0; i < n; i++)
    {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

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

int main()
{
    int u, k, v;

    cin >> n;

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

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

    dfs();

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    d[u] = ++tt; // 最初の訪問
    for (v = 0; v < n; v++) {
        if (M[u][v] == 0) continue;
        if (color[v] == WHITE) dfs_visit(v);
    }
    color[u] = BLACK;
    f[u] = ++tt; // 訪問の完了
}

void dfs() {
    int u;
    for (u = 0; u < n; u++) {
        color[u] = WHITE;
    }
    tt = 0;

    for (u = 0; u < n; u++) {
        // 未訪問のuを始点として深さ優先探索
        if (color[u] == WHITE) dfs_visit(u);
    }
    for (u = 0; u < n; u++) {
        cout << u+1 << " " << d[u] << " " << f[u] << endl;
    }
}

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

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

    dfs();

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int d[100];
int f[100];
int now = 1;
void dfs(vector<vector<int> > v, int i) {
  if (d[i]) return;
  d[i] = now++;
  for (int vv : v[i])
    if (i != vv) dfs(v, vv);
  f[i] = now++;
}

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

  vector<vector<int> > v(n);
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    vector<int> vv(k);
    rep(j, k) {
      cin >> vv[j];
      vv[j]--;
    }
    v[i] = vv;
  }

  rep(i, n) if (!d[i]) dfs(v, i);
  rep(i, n) { printf("%d %d %d\n", i + 1, d[i], f[i]); }
  return 0;
}