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>
#include<vector>
#include<utility>
using namespace std;
vector<int> l[101];
int matrix[100][100];
pair<int,int> t[101];
bool visited[101];
int tim=0;
void dfs(int cur)
{
    tim+=1;
    t[cur].first=tim;
    //cerr<<"visiting "<<cur<<' '<<tim<<endl;
    visited[cur]=true;
    
    for(int i=0;i<l[cur].size();i++)
    {
        if((matrix[cur-1][l[cur][i]-1]==1)&&(visited[i]==false))
        {
            dfs(l[cur][i]);
        }
    }
    
    tim+=1;
    t[cur].second=tim;
    
    
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            int tmp;
            cin>>tmp;
            l[u].push_back(tmp);
        }
    }
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            matrix[i][j]=0;
        }
    }
    for(int i=1;i<n+1;i++)
    {
        visited[i]=false;
        for(int j=0;j<l[i].size();j++)
        {
            matrix[i-1][l[i][j]-1]=1;
        }
    }
    
    for(int i=1;i<n+1;i++)
    {
        if(visited[i]==false)
            dfs(i);
    }
    
    for(int i=1;i<n+1;i++)
    {
        cout<<i<<" "<<t[i].first<<" "<<t[i].second<<endl;
    }
}

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

using std::cin;
using std::cout;

struct vertex {
    int vv;
    int ww;
};

//enum class VColor {White, Gray, Black};
typedef enum {White, Gray, Black} VColor;

void
dfsearch(std::vector<vertex> *gar, int gsz, int uu,
         std::vector<VColor> &color,
         std::vector<int> &dd, std::vector<int> &ff, std::vector<int> &prev,
         int &cnt)
{
    color[uu] = Gray;
    dd[uu] = ++cnt;
    //cout << uu << " " << cnt << std::endl;
    std::vector<vertex>::iterator it = gar[uu].begin();
    for (; it != gar[uu].end(); it++) {
        int     vv = (*it).vv;
        if (color[vv] == White) {
            prev[vv] = uu;
            dfsearch(gar, gsz, vv, color, dd, ff, prev, cnt);
        }
    }
    
    color[uu] = Black;
    ff[uu] = ++cnt;
    return;
}

int
main()
{
    int vn;
    std::vector<vertex> gar[100 + 1];

    cin >> vn;
    for (int idx = 0; idx < vn; idx++) {
        int uu;
        int kk;
        int vv;

        cin >> uu >> kk;
        for (int ik = 0; ik < kk; ik++) {
            cin >> vv;
            gar[uu].push_back({vv, 1});
        }
    }

#if 0
    for (int uu = 1; uu <= vn; uu++) {
        std::vector<vertex>::iterator it = gar[uu].begin();
#if 0
        for (; it != gar[uu].end(); it++) {
            printf("v = %d w = %d\n", (*it).vv, (*it).ww);
        }
#else
        for (int vv = 1; vv <= vn; vv++) {
            if (vv != 1) cout << ' ';
            if ((it != gar[uu].end()) && ((*it).vv == vv)) {
                cout << '1';
                it++;
            } else {
                cout << '0';
            }
        }
        cout << std::endl;
#endif
    }
#endif

    std::vector<VColor> color;
    std::vector<int> dd;
    std::vector<int> ff;
    std::vector<int> prev;
    int counter;

    color.assign(vn + 1, White);
    dd.assign(vn + 1, 0);
    ff.assign(vn + 1, 0);
    prev.assign(vn + 1, 0);

    counter = 0;
    dfsearch(gar, vn, 1, color, dd, ff, prev, counter);
    std::vector<VColor>::iterator cit = color.begin();
    for (cit++; cit != color.end(); cit++) {
        if (*cit == White) {
            dfsearch(gar, vn, std::distance(color.begin(), cit), color,
                     dd, ff, prev, counter);
        }
    }

    for (int uu = 1; uu <= vn; uu++) {
        cout << uu << " " << dd[uu] << " " << ff[uu] << std::endl;
    }
}

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

struct Node {
	int in, out;
	bool flag = false;
	vector<int> v;
};

int dfs(vector<Node>& u, int id, int d)
{
	if (u[id].flag) return d - 1;

	int a;
	u[id].in = d;
	u[id].flag = true;
	for (int i = 0; i < u[id].v.size(); i++)
	{
		d = dfs(u, u[id].v[i], d + 1);

	}
	u[id].out = d + 1;
	return d + 1;
}

int main(void)
{
	int N, id, k, x;
	Node z;
	cin >> N;
	vector<Node> u(N + 1);
	for (int i = 0; i < N; i++)
	{
		cin >> id >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> x;
			u[id].v.push_back(x);
		}
	}

	int d = 0;
	for(int i = 1; i <= N; i++) d = dfs(u, i, d + 1);

	for (int i = 1; i <= N; i++) cout << i  << " " << u[i].in << " " <<  u[i].out << endl;

	return 0;
}

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

vector<int> graph[100];
int d[100], f[100];
int visited = 0;

void dfs(int id){
    d[id] = visited++;
    for(int i = 0; i < graph[id].size(); i++)
	{
        if(graph[id][i] != id && !d[graph[id][i]] && !f[graph[id][i]])
		{
			dfs(graph[id][i]);
		}
    }
    f[id] = visited++;
}

int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++)
	{
        int u, k;
        cin >> u >> k;
        for(int j = 0;j < k;j++)
		{
            int v;
            cin >> v;
            graph[u - 1].push_back(v - 1);
        }
    }
    dfs(0);
    for(int i = 0;i < n;i++)
	{
        if(!f[i]) 
		{
			dfs(i);
		}
    }
    for(int i = 0;i < n;i++)
	{
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}