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

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 100;

int adj_matrix[N_MAX+1][N_MAX+1];

int d[N_MAX+1];
int f[N_MAX+1];

stack<int> route;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    int id, k, v;
    FOR(i,0,n) {
        cin >> id;
        cin >> k;
        FOR(j,0,k) {
            cin >> v;
            adj_matrix[id][v] = 1;
        }
    }

    const int TIMELIMIT = 2 * n;

    int cur = 1;
    route.push(0);

    FOR(t,1,TIMELIMIT) {
        if (!d[cur]) {
            d[cur] = t;
        }
        int next = 0;
        FOR(i,1,n+1) {
            if (adj_matrix[cur][i] && !d[i]) {
                next = i;
                break;
            }
        }
        if (next == 0) {
            f[cur] = t + 1;
            cur = route.top();
            route.pop();
        } else {
            route.push(cur);
            cur = next;
        }
    }

    FOR(i,1,n+1) {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

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

struct Graph {
    enum Color {WHITE, GRAY, BLACK};
    vector<vector<int>> adj;
    vector<Color> color;
    vector<int> tstart;
    vector<int> tend;
    int time;
    Graph(int n) {
        adj.assign(n, vector<int>());
        color.assign(n, WHITE);
        tstart.assign(n, 0);
        tend.assign(n, 0);
        time = 0;
    }
};

void dfs(Graph& g, int u)
{
    g.color[u] = Graph::GRAY;
    g.tstart[u] = ++g.time;
    for (auto v : g.adj[u]) {
        if (g.color[v] == Graph::WHITE) {
            dfs(g, v);
        }
    }
    g.tend[u] = ++g.time;
    g.color[u] = Graph::BLACK;
}

int main()
{
    int n;
    cin >> n;
    Graph g(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;
            g.adj[u - 1].push_back(v - 1);
        }
    }

    for (int i = 0; i < n; i++) {
        if (g.color[i] == Graph::WHITE) {
            dfs(g, i);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << (i + 1) << " " << g.tstart[i] << " " << g.tend[i] << endl;
    }
}

C++: #include<iostream>
const int MAXN = 105;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int a[MAXN][MAXN];
int color[MAXN];
int d[MAXN];
int f[MAXN];
int n, tt = 0;
using namespace std;

void dfs(int u)
{
	int v;
	d[u] = ++tt;
	for(v = 0; v < n; v++)
	{
		if(a[u][v] == 0)
			continue;
		if(color[v] == WHITE)
		{
			color[v] = GRAY;
			dfs(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs_init()
{
	int u;
	for(u = 0; u < n; u++)
		color[u] = WHITE;
	
	for(u = 0; u < n; u++)
	{
		if(color[u] == WHITE)
			dfs(u);
	}
	
	for(u = 0; u < n; u++)
	{
		cout << u+1 << " " << d[u] << " " << f[u] << endl;	
	}	
} 

int main ()
{
	int k, u, temp;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> u >> k;
		u--;
		for(int j = 0; j < k; j++)
		{
			cin >> temp;
			temp--;
			a[u][temp] = 1;
		}
	}
	dfs_init();
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long
const int dx[4] = { 1,-1,0,0 };
const int dy[4] = { 0,0,1,-1 };
bool OOA(int x,int y,int H,int W){return (0<=x&&x<H)&&(0<=y&&y<W);}

struct Graph{
	int V,E,t;
	vector<int>cost;
	vector<int>d;
	vector<int>f;
	vector<bool>vzt;
	vector<vector<int>>adj;
	void init(int dflt){//dflt!=0
		t=1;
		adj=vector<vector<int>>(V+1);
		cost = vector<int>(V + 1, dflt);
		d = vector<int>(V + 1, dflt);
		f = vector<int>(V + 1, dflt);
		vzt=vector<bool>(V+1,false);
	}

	void bfs(int s, int scost){
		queue<pair<int,int>>q;
		q.push({scost,s});
		vzt[s]=true;
		cost[s]=0;
		while(!q.empty()){
			auto top=q.front();
			q.pop();
			int cst=top.first,now=top.second;
			for(int i=0;i<adj[now].size();i++){
				if(!vzt[adj[now][i]]){
					vzt[adj[now][i]]=true;
					cost[adj[now][i]]=cost[now]+1;
					q.push({cost[adj[now][i]],adj[now][i]});
				}
			}
		}
	}

	void dfs(int now){
		if(d[now]==-1){d[now]=t;t++;}
		else return;
		for(int i=0;i<adj[now].size();i++)dfs(adj[now][i]);
		if(f[now]==-1){f[now]=t;t++;}
		return;
	}
};

int n;
Graph G;

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

C++: #include<iostream>
int s[100]={0},f[100]={0},B[100][100]={0},A[100]={0},d[100],c[100]={0},cnt=1,tmp;
bool con(int A[],int n){
	for(int i=0;i<n;i++){
		if(A[i]==0){
			tmp=i;
			return true;
		}
	}
	return false;
}
void search(int v){
  A[v]=1;
  s[v]=cnt++;
  for(int i=0;i<d[v];i++){
    if(A[B[v][i]]==0){
      search(B[v][i]);
    }
  }
  f[v]=cnt++;
}
int main(){
  int n,num,flag;
  std::cin>>n;
  for(int i=0;i<n;i++){
    std::cin>>num>>d[i];
    for(int j=0;j<d[i];j++){
      std::cin>>flag;
      B[num-1][j]=flag-1;
    }
  }
  search(0);
	while(con(A,n)){
		search(tmp);
	}
  for(int i=0;i<n;i++){
    std::cout<<i+1<<" "<<s[i]<<" "<<f[i]<<"\n";
  }
  return 0;
}