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 <bits/stdc++.h>

using namespace std;
typedef long long ll;

// #define DEBUG

int set_time = 1;
const int maxint = 1000;
struct timestamp;
vector<int> color;
vector<timestamp> ts;
vector< vector<int> > connective;

struct timestamp
{
    int node;
    int discoverry_time;
    int terminate_time;
};

void init_ts(int n, timestamp *a)
{
    a->node = n;
    a->discoverry_time = -1;
    a->terminate_time = -1;
}

void disp_ts(timestamp a)
{
    cout << a.node + 1 << " " << a.discoverry_time << " " << a.terminate_time << endl;
}

void dfs(int x, timestamp *a, vector<int> v)
{
    color[x] = 1;
    a->discoverry_time = set_time;
    set_time++;
    for (auto itr = v.begin(); itr != v.end(); itr++)
    {   
        if (color[*itr] == -1)
            dfs(*itr, &ts[*itr], connective[*itr]);
    }

    a->terminate_time = set_time;
    set_time++;
    
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, v, k, x;
    cin >> n;
    timestamp tsi;
    connective.resize(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v >> k;
        color.push_back(-1);
        init_ts(i, &tsi);
        ts.push_back(tsi);
        for (int j = 0; j < k; j++)
        {
            cin >> x;
            connective[i].push_back(x-1);
        }
        
    }
    for (int i = 0; i < n; i++){
        if (color[i] == -1)
            dfs(i, &ts[i], connective[i]);
    }

    for_each(ts.begin(), ts.end(), disp_ts);

    return 0;
}


// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)

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 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])
            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();
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
using namespace std;

int n = 0;
int u = 0;
int k[100];
int v[100][100];
int Discover[100] = { 0 };
int End[100] = { 0 };
//int nx = 0;
int p = 0;
void dfs(int l) {
	int i;
	int j;
	if (!Discover[l]) {
		Discover[l] = ++p;

		for (i = 0; i < n + 1; i++) {
			if (v[l][i]) {
				dfs(v[l][i]);
			}
		}
		End[l] = ++p;
	}
}
int main()
{
	int i;
	int j;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u ;
		cin >> k[u];
		for (j = 0; j < k[u]; j++) {
			cin >> v[u][j];
		}
	}
	for (i = 1; i < n + 1; i++) {
		if (!Discover[i]) {
			dfs(i);
		}
	}
	for (i = 1; i < n + 1; i++) {
		cout << i << " " << Discover[i] << " " << End[i] << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std; 
struct TIMECOUNT {
	int d, f;
};
int main()
{
	int n, u, k, vv, time = 0;
	cin >> n;
	vector<TIMECOUNT> timecount(n);
	for (int variable = 0; variable < n; ++variable) {
		timecount[variable].d = 0;
		timecount[variable].f = 0;
	}
	vector<int> a;
	vector< vector<int> > v(n);
	for (int variable1 = 0; variable1 < n; ++variable1) {
		cin >> u >> k;
		for (int variable2=0; variable2 < k; ++variable2) {
			cin >> vv;
			v[variable1].push_back(vv);	
		}
		sort(v[variable1].begin(), v[variable1].end());
	}
	a.push_back(1);
	while (timecount[0].f == 0) {
		while (v[a.back() - 1].size() != 0) {
			++time;
			timecount[a.back() - 1].d = time;
			for (int variable = 0; variable < v[a.back() - 1].size(); ++variable) {
				if (timecount[v[a.back() - 1][variable] - 1].d == 0)
					a.push_back(v[a.back() - 1][variable]);
				else
					break;
			}
		}
		while (v[a.back() - 1].size() == 0) {
			++time;
			timecount[a.back() - 1].f = time;
			a.pop_back();
		}
	}
	for (int i = 0; i < n; ++i) {
		cout << i + 1 << " " << timecount[i].d << " " << timecount[i].f << endl;
	}
}