Go: package main

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

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <list>
#define black 0
#define red 1
#define white -1
#define maxn 110
using namespace std;

int tot = 0;
int book[maxn] = {}, t[maxn][2] = {};
list<int> map[maxn];

void dfs(int u)
{
	if (book[u] == white) return; 
	else
		if (book[u] == black)
		{
			t[u][0] = ++tot;
			for (list<int>::iterator it = map[u].begin(); it != map[u].end(); it++)
				dfs(*it-1);
			book[u] = white;
			t[u][1] = ++tot;
		}
	return;
}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int u,k,v;
		scanf("%d%d", &u,&k);
		u--;
		for (int i = 0; i < k; i++)
		{
			scanf("%d", &v);
			map[u].push_back(v);
		}
	}
	for(int i=0;i<n;i++)
		if(book[i]==black)
	       dfs(i);
	for (int i = 0; i < n; i++)
	{
		printf("%d %d %d", i + 1, t[i][0], t[i][1]);
		if (i != n - 1)printf("\n");
	}
	return 0;
}

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

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

void dfs_visit(int u) {
	color[u] = GRAY;
	d[u] = ++tt;
	for (int v = 0; v < n; v++) {
		if (M[u][v] == 1 && color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs_print() {
	for (int i = 0; i < n; i++) color[i] = WHITE;
	tt = 0;
	for (int i = 0; i < n; i++) {
		if (color[i] == WHITE) {
			dfs_visit(i);
		}
	}

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

int main() {
	cin >> n;
	int u, k;
	int index;

	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;
		for (int j = 0; j < k; j++) {
			cin >> index;
			M[u - 1][index - 1] = 1;
		}
	}
	dfs_print();
}

C++: #include <stack>
#include <stdio.h>
#include <vector>

using namespace std;

#define NMAX 100
#define NIL -1

int d[NMAX + 1];           // start time, 1-origin
int f[NMAX + 1];           // finish time, 1-origin
stack<int> S;              // visited but not finished
vector<int> adj[NMAX + 1]; // adj
int n = 0;
int cnt = 0;

int next_unvisited_adj(int u) { // next not visited adj of u
    for (vector<int>::iterator it = adj[u].begin(); it != adj[u].end(); it++) {
        if (d[*it] == 0) // not finished
            return *it;
    }
    return NIL;
}

int next_unvisited() {
    for (int i = 1; i <= n; i++) {
        if (d[i] == 0)
            return i;
    }
    return NIL;
}

void dfs() {
    int x; // start vertex
    while ((x = next_unvisited()) != NIL) {
        // printf("dfs component of %d\n", x);
        S.push(x);
        d[x] = ++cnt;
        while (!S.empty()) { // dfs this component
            // check if the last visited guy is finished
            // if yes, pop it from the stack
            // if no, push the next unfinished adj of it
            int u = S.top();
            // printf("u=%d\n", u);
            int v = next_unvisited_adj(u);
            if (v != NIL) {
                if (d[v] == 0) { // v is not visited
                    // printf("%d is found\n", v);
                    d[v] = ++cnt;
                    S.push(v);
                }
            } else { // u is finished
                // printf("%d is finished\n", u);
                S.pop();
                f[u] = ++cnt;
            }
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        d[i] = 0; // not visited
        f[i] = 0; // not finished
    }
    for (int i = 0; i < n; i++) {
        int u, k, v;
        scanf("%d", &u);
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            scanf("%d", &v);
            adj[u].push_back(v);
        }
    }
    dfs();
    for (int i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

    return 0;
}

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

#define N_MAX 100
#define WH 0
#define GR 1
#define BK 2

long n;
long ttime = 0;
long G[N_MAX][N_MAX] = {};
long D[N_MAX], F[N_MAX];
long color[N_MAX] = {};

void dfs_rec(long u) {
    color[u] = GR;
    ttime++;
    D[u] = ttime;
    // cout << "start time " << u << ": " << D[u] << endl;

    for (long v = 0; v < n; v++) {
        // cout << "(u, v) = (" << u << ", " << v << ")" << endl;
        if (G[u][v] == 1 && color[v] == WH) {
            dfs_rec(v);
        }
    }
    color[u] = BK;
    ttime++;
    F[u] = ttime;
    // cout << "end time " << u << ": " << F[u] << endl;
}

int main() {
    long v_from, deg_out, v_to;

    cin >> n;
    for (long i = 0; i < n; i++) {
        cin >> v_from >> deg_out;
        v_from--;
        for (long j = 0; j < deg_out; j++) {
            cin >> v_to;
            v_to--;
            G[v_from][v_to] = 1;
        }
    }

    // for (long i = 0; i < n; i++) {
    //     for (long j = 0; j < n; j++) {
    //         if (j != 0) { cout << " "; }
    //         cout << G[i][j];
    //     }
    //     cout << endl;
    // }

    for (long u = 0; u < n; u++) {
        if (color[u] == WH) {
            dfs_rec(u);
        }
    }

    for (long i = 0; i < n; i++) {
        cout << i + 1 << " " << D[i] << " " << F[i] << endl;
    }

    return 0;
}