Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

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

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N+1)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fi first
#define se second
using Graph=vector<vector<int>>;

void dfs(int s,Graph graph,vector<int> &d,vector<int> &f,int &flag1,int &flag2)
{
	int n=graph.size();
	d[s]=flag1;
	flag1++;
	for (int i=0;i<n;i++)
	{
		if (graph[s][i]==1 && d[i]==-1) dfs(i,graph,d,f,flag1,flag2);
	}
	f[s]=flag2;
	flag2++;
}
int main()
{
	int n;cin >> n;
	Graph graph(n,vector<int> (n,0));
	int u,k,v;
	for (int i=0;i<n;i++)
	{
		cin >>u;
		cin >>k;
		for (int j=0;j<k;j++)
		{
			cin >>v;
			graph[u-1][v-1]=1;
		}
	}
	int flag1=1,flag2=1;
	vector<int> d(n,-1),f(n-1);
	for (int i=0;i<n;i++)
	{
		if (d[i]==-1) dfs(i,graph,d,f,flag1,flag1);
	}
	
	for (int i=0;i<n;i++)
	{
		cout <<i+1 <<" " << d[i] <<" " << f[i] << endl;
	}
	return 0;
}

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

using namespace std;

int n, u, k, v, d[110], f[110], tim=0;
bool vis[110];
vector<int> adj[110];

void dfs (int p)
{
    tim++;
    vis[p]=true;
    d[p]=tim;
    for (auto u : adj[p])
    {
        if (!vis[u]) dfs(u);
    }
    tim++;
    f[p]=tim;
}

int main()
{
    memset(vis, false, sizeof(vis));
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>u>>k;
        for (int j=0; j<k; j++)
        {
            cin>>v;
            adj[u].push_back(v);
        }
    }
    for (int i=1; i<=n; i++)
    {
        if (!vis[i]) dfs(i);
    }
    for (int i=1; i<=n; i++)
    {
        cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
    }
    return 0;
}

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

using namespace std;
int n,u,k;

class points{
    public:
    int flag=0;
    list<int> l;
    int d=0;
    int f=0;
}pt[110];
int tem;

int times=0;

void dfa(int cur){
    times+=1;
    pt[cur].d=times;
    pt[cur].flag=1;
    while(!pt[cur].l.empty()){
        int dst=pt[cur].l.front();
            if(pt[dst].flag==0){
                dfa(dst);
            }
        pt[cur].l.pop_front();
    }
    times+=1;
    pt[cur].f=times;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>tem;
            pt[u].l.push_back(tem);
        }
    }
    for(int i=1;i<=n;i++){
        if(pt[i].flag==0){
            dfa(i);
        }
    }
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<pt[i].d<<" "<<pt[i].f<<endl;
    }
    
}

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 color[N], d[N], f[N], tt;
int nt[N];

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

void dfs_visit(int M[N][N], int n, 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(M, n, 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(int M[N][N], int n) {
    for (int i = 0; i < n; ++i) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

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

int main() {

    int n;
    cin >> n;

    int M[N][N] = {0};
    int u, k, v;
    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(M, n);

    return 0;
}

C++: #include<stdio.h>

#define WHITE 0   // not visited yet.
#define GRAY 1    // visited, but not completed.
#define BLACK 2   // search completed.

int G[101][101];        // adjacency list.
int color[101];         // visited/completed sign.
int n;                  // size.
int d[101], f[101], t;  // first visit time/complete time.

void search_loop(int i) 
{
    int next;
    d[i] = ++t;
    color[i] = GRAY;  // first visited.

    for(next = 1; next <= n; next++){
        if(i == next && G[i][i] > 0) break;   // if self-looped, through.
        if(G[i][next] > 0 && color[next] == WHITE){  // if not visited yet, visit.
            search_loop(next);
        }
    }
    f[i] = ++t;
    color[i] = BLACK;  // completed. 

    return;
}

void dfs()
{
    int i;
    for(i = 1; i <= n; i++) color[i] = WHITE;  // initialize.
    t = 0;

    for(i = 1; i <= n; i++) if(color[i] == WHITE) search_loop(i);

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

    return ;
}

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

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

    dfs();
    return 0;
}