Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

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

using namespace std;

const int max_v = 100;
vector<vector<int> > adj_list;
int d[max_v] = { 0 };
int f[max_v] = { 0 };
int discovered[max_v] = { 0 };
int t = 1;

// Depth-first Search ( Stack implementation)
void DFS(int v)
{
	stack<int> S;
	S.push(v);
	discovered[v] = 1;
	d[v] = t++;
	int i = 0;
	while (!S.empty()) {
		v = S.top();
		if (i < adj_list[v - 1].size()) {
			int u = adj_list[v - 1][i++];
			if (discovered[u] == 0) {
				discovered[u] = 1;
				d[u] = t++;
				S.push(u);
				i = 0;
			}
		}
		else {
			S.pop();
			f[v] = t++;
			i = 0;
		}
	}
}

int main(int argc, char** argv)
{
	// Input
	int n;
	int u, k;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		int v;
		vector<int> adj;
		for (int j = 0; j < k; j++) {
			cin >> v;
			adj.push_back(v);
		}
		adj_list.push_back(adj);
	}

	// Depth-first Search
	DFS(1);

	// Output
	for (int i = 1; i <=n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include "memory.h"
#include <stack>

using namespace std;

bool matrix[100][100];
int n;

int next(int k){
	for(int i = 0; i < n; i++){
		if(matrix[k][i] == true)
			return i + 1;
	}
	return false;
}

int main(){
	int index, temp, num, current, count = 1;
	int start_end[100][2];
	stack<int> back;

	memset(matrix, 0, sizeof(matrix));
	memset(start_end, 0, sizeof(start_end));

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> index >> num;
		while(num--){
			cin >> temp;
			matrix[index-1][temp-1] = true;
		}
	}
	back.push(0);
	current = 0;
	while(!back.empty()){
		int r;
		r = next(current);
		if(start_end[current][0] == 0){
			start_end[current][0] = count;
			count++;
		}
		if(r){
			matrix[current][r-1] = false;
			back.push(current);
			current = r - 1;
		}
		else{
			if(start_end[current][1] == 0){
				start_end[current][1] = count;
				count++;
			}
			current = back.top();
			back.pop();
		}
		
	}
	for(int i = 0; i < n; i++){
		cout << i + 1 << " " << start_end[i][0] << " " << start_end[i][1] << endl;
	}


}

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

int n,m[101][101];
int d[101],f[101],t=0,vis[101];

void dfs(int u){
    if(vis[u]) return;
    vis[u] = 1;
    d[u] = ++t;
    for( int i = 1; i <= n; i++ ){
        if( vis[i]==0 && m[u][i] ){
            dfs(i);
        }
    }
    f[u] = ++t;
}

int main(){
    int i,j,k,u,v,du;
    scanf("%d",&n);
    k = n;
    while(k--){
        scanf("%d",&u);
        scanf("%d",&du);
        while(du--){
            scanf("%d",&v);
            m[u][v]  = 1;
        }
    }
    for( i = 1; i <= n; i++ ){
        dfs(i);
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack<int> st;
int  v[102][101], n;
int  tim[102][2];
int ct = 1;
int go[102];
inline void search(int t) {
	if(!tim[t][0]) tim[t][0] = ct++;
	go[t] = 1;
	int tf = 0;
	for (int a = 1; a <= n; a++) {
		if (v[t][a]) {
			st.push(a);
			for (int i = 1; i <= n; i++) {
				v[i][a] = 0;
			}
			search(st.top());
			tf = 1;
		}
	}
		
	if(!tf) {
		st.pop();
		tim[t][1] = ct++;
		if(!st.empty()) search(st.top());
	}
}
int main() {

	st.push(1);
	int u, k, s;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			v[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			v[u][s] = 1;
		}
	}
	search(1);
	for (int i = 2; i <= n; i++) {
		if (!go[i]) search(i);
	}
	for (int i = 1; i <= n; i++) {
		cout << i << " " << tim[i][0] << " " << tim[i][1] << endl;
	}
	return 0;
}

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

class Adjl{
private:
	int u;
	int k;
	Adjl **next;
protected:
	int d;
	int f;
public:
	Adjl(int u);
	~Adjl(){ if (next != NULL) delete[] next; }
	void setV(int k, Adjl *vk);
	int depthFirstSearch(int time);
	void print();
};

Adjl::Adjl(int u)
{
	this->u = u;
	k = 0;
	next = NULL;
	d = 0;
	f = 0;
}

void Adjl::setV(int k, Adjl *vk)
{
	if (this->k == 0) next = new Adjl*[k];
	next[this->k] = vk;
	(this->k)++;
}

int Adjl::depthFirstSearch(int time)
{
	if (d != 0) return time;
	time++;
	d = time;
	for (int i = 0; i < k; i++) {
		time = next[i]->depthFirstSearch(time);
	}
	time++;
	f = time;
	return time;
}

void Adjl::print()
{
	cout << u << " " << d << " " << f << endl;
}

int main(void)
{
	int n;
	cin >> n;
	
	Adjl **adjl = new Adjl*[n];
	int check[100] = {0};

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		if (check[i] == 0) {
			adjl[i] = new Adjl(u);
			check[i] = 1;
		}
		check[i] = 1;
		for (int j = 0; j < k; j++) {
			int vk;
			cin >> vk;
			if (check[vk - 1] == 0) {
				adjl[vk - 1] = new Adjl(vk);
				check[vk - 1] = 1;
			}
			adjl[i]->setV(k, adjl[vk - 1]);
		}
	}

	int time = 0;
	for (int i = 0; i < n; i++) {
		time = adjl[i]->depthFirstSearch(time);
	}

	for (int i = 0; i < n; i++) {
		adjl[i]->print();
	}

	delete[] adjl;
	return 0;
}

C++: #include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

vector<vector <int>> v;
int color[100],d[100],f[100],t,n;

void dfs_visit(int u)
{
	color[u]=1;
	d[u]=++t;
	int next=-1;
	rep(i,v[u].size())
	{
		if(color[v[u][i]]==0)
		{
			next=v[u][i];
			dfs_visit(next);
		}
	}
	f[u]=++t;
}

void dfs()
{
	rep(i,n)color[i]=0;
	t=0;

	rep(i,n)
	{
		if(color[i]==0)dfs_visit(i);
	}
}

int main()
{
	cin >> n;
	rep(i,n)
	{
		int hoge;cin >> hoge;
		int k;cin >> k;
		v.push_back(vector <int>());
		rep(j,k)
		{
			int fooo; cin >> fooo;
			v[i].push_back(fooo-1);
		}
	}

	dfs();
	rep(i,n)
	{
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
	}
	return 0;
}