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)
	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<iostream>
using namespace std;
#include<stdio.h>

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

typedef struct box{ int val; box* next; } box_t;  // stack.

box_t* init()
{
    box_t* head = new box_t;
    head->val = -1;
    head->next = NULL;
    return head;
}

bool isEmpty(box_t* head){ return (head->next == NULL ? true : false); }

box_t* push(box_t* head, int data)
{
    box_t* box = new box_t;
    box->val = data;
    box->next = head->next;
    head->next = box;
    return box;
}

int pop(box_t* head)
{
    if(isEmpty(head)){ return -1; }
    box_t* box = head->next;
    int val;
    head->next = box->next;
    val = box->val;
    delete box;
    return val;
}

int front(box_t* head)
{
    int val;
    if(isEmpty(head)){ return -1; }
    val = head->next->val;
    return val;
}

box_t* stack = init();

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

int main()
{
    int n, i, j, a, b, e;
    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++){
        cout << i << " " << found[i] << " " << comp[i] << endl;
    }
    return 0;
}

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

int N;
int G[101][101];
int visited[101];

int start[101], complete[101];

int dfs(int v, int t) {
    visited[v] = 1;
    start[v] = t;
    int nt = t+1;
    for (int j = 0; j <= N; ++j) {
        if (!visited[j] && G[v][j]) {
            nt = dfs(j, nt);
        }
    }
    complete[v] = nt;
    return nt+1;
}

int main() {
    cin >> N;
    for (int j = 0; j <= N; ++j) for (int k = 0; k <= N; ++k) G[j][k] = 0;
    for (int j = 0; j <= N; ++j) visited[j] = 0;
    for (int _ = 0; _ < N; ++_) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v; cin >> v;
            G[u][v] = 1;
        }
    }

    int tt = 1;
    for (int j = 1; j <= N; ++j) {
        if (!visited[j]) tt = dfs(j, tt);
    }

    for (int j = 1; j <= N; ++j) {
        cout << j << " " << start[j] << " " << complete[j] << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 20001;

int G[101][101];
int color[101], d[101], f[101];
int t = 0;

void dfs(int u, int n)
{
	color[u] = 1;
	d[u] = ++t;
	for (int v = 1; v <= n; v++) {
		if (G[u][v] && color[v] == 0)
			dfs(v, n);
	}
	color[u] = 1;
	f[u] = ++t;
}

int main(void)
{
	int n, k, v, u;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int i = 0; i < k; i++) {
			cin >> v;
			G[u][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (color[i] == 0)
			dfs(i, n);
	}
	for (int i = 1; i <= n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

C++: // ALDS1_11_B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

vector<vector<int>> node(101);
vector<int> setu(101);
vector<bool> seen(101,false); 
vector<int> start(101,0);
vector<int> goal(101,0);
int t=0;
void dfs(int x){
    if(seen[x]==true) return;
    seen[x]=true;
    t++;
    start[x]=t;
    rep(i,setu[x]){
        dfs(node[x][i]);
    }
    t++;
    goal[x]=t;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n;
    cin>>n;
    rep(i,n){
        int u,k;
        cin>>u>>k;
        rep(j,k){
            int v;
            cin>>v;
            node[u].push_back(v);
            setu[u]=k;
        }
    }
    for(int i=1;i<=n;i++){
        dfs(i);
    }
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<start[i]<<" "<<goal[i]<<endl;
    }
    return 0;
}