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;
#include<stdio.h>

class stack
{
    int S[101], top, MAX;
public:
    stack();
	void initialize(){ top = 0; MAX = 101; }
	void push(int x){ top++; S[top] = x; }
	int pop(){ top--; return S[top + 1]; }
	int front(){ return S[top]; }
	bool isEmpty(){ return top == 0; }
};

stack::stack(){}

int G[101][102];
int found[101];
int comp[101];   // complete.
int t;  // time.

stack box = stack();

void search_loop(int i)
{
    int j, k;
    while(1){
        if(found[i] == 0){
            t++; found[i] = t;
            box.push(i);
        }
        for(k = G[i][0]; G[i][k] != 0 && found[G[i][k]] != 0; k++);
        if(G[i][k] == 0){
            if(box.isEmpty()){ return; }
            else{
                j = box.pop();
                t++; comp[j] = t;
                i = box.front();
            }
        }else{
            G[i][0] = k + 1;
            i = G[i][k];
        }
    };
    return;
}

int main()
{
    int n, i, j, a, b, e;
	box.initialize();

    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        G[i][0] = 1;
        for(j = 1; j <= n + 1; j++){ G[i][j] = 0; } }

    for(i = 1; i <= n; i++){
        scanf("%d %d", &a, &e);
        for(j = 1; j <= e; j++){
            scanf("%d", &b); G[a][j] = b; } }  // adjacent representation.

    for(i = 1; i <= n; i++){ found[i] = 0; comp[i] = 0; }
    t = 0;
    while(1){
        for(i = 1; i <= n; i++){
            if(found[i] == 0) break;
        }
        if(i > n) break;
        search_loop(i);
    };

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

C++: #include <iostream>

using namespace std;

const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int n = 0;
int color[N];
int M[N][N];
int 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++)
    {
        if(color[u]==WHITE)
            dfs_visit(u);
    }
    for(u=0;u<n;u++)
        cout << u+1 << " " << d[u] << " " << f[u] << "\n";
}

int main()
{
    int u,k,v,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 <cstdio>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

using Weight=int;
using DArray=vector<Weight>;
using DMatrix=vector<DArray>;

static const Weight INF=1<<29;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

void dfs(const Graph &g, size_t v, int &t, vector<int> &d, vector<int> &f) {
    d[v] = t;
    for (const Edge &e: g[v])
        if (!d[e.dst])
            dfs(g, e.dst, ++t, d, f);

    f[v] = ++t;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Graph g(n);
    for (size_t i=0; i<n; ++i) {
        size_t k;
        scanf("%*d %zu", &k);
        for (size_t j=0; j<k; ++j) {
            size_t v;
            scanf("%zu", &v);
            --v;

            connect(g, i, v);
        }
    }

    vector<int> d(n), f(n);
    int t=1;
    dfs(g, 0, t, d, f);

    for (size_t i=0; i<n; ++i)
        printf("%zu %d %d\n", i+1, d[i], f[i]);

    return 0;
}

C++: #include <cstdio>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N];
//??\??¶????????°??¶???
int d[N];
//??\??¶???????????¶???
int f[N];
//??¶???
int tt;

//??¨???????????°?????°?????±?????????????´¢
void dfs_visit(int u){
    int v;
    //??£??¨???????????°
    color[u]=GRAY;
    //??¶????????°
    d[u]=++tt;
    for(v=0;v<n;v++)
        if(M[u][v]&&color[v]==WHITE)
            dfs_visit(v);
    //????????????
    color[u]=BLACK;
    f[u]=++tt;
}

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

    for(int u=0;u<n;u++)
        //??\????????????u?????????????????±?????????????´¢
        if(color[u]==WHITE)
            dfs_visit(u);
    for(int u=0;u<n;u++)
        printf("%d %d %d\n",u+1,d[u],f[u]);
}

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

    scanf("%d",&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++){
        scanf("%d %d",&u,&k);
        u--;
        for(int j=0;j<k;j++){
            scanf("%d",&v);
            v--;
            M[u][v]=1;
        }
    }

    dfs();
}

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

int m[101][101];
int visit[101];
int d[101];
int f[101];
int n, t;

void dfs(int u){
  visit[u] = 1;
  d[u] = t;
  t++;
  
  for(int i = 0; i < n; ++i){
    if(m[u][i] == 1 && visit[i] == 0){
      dfs(i);
    }
  }

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

main()
{
  int u, k, v;
  t = 1;

  cin >> n;
  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; 
    //隣接行列
    }
  }

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

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

  return (0);
}