Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type nodeKey int

type DirectedGraphNode struct {
	key       nodeKey
	adjacents []*DirectedGraphNode
	visited   bool
	d         int
	f         int
	parent    *DirectedGraphNode
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(l, r nodeKey) {
	g.nodes[l].adjacents = append(g.nodes[l].adjacents, g.nodes[r])
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for iNodes := 0; iNodes < nNodes; iNodes++ {
		graph.nodes[iNodes] = &DirectedGraphNode{}
		graph.nodes[iNodes].key = nodeKey(iNodes)

		graph.nodes[iNodes].visited = false
		graph.nodes[iNodes].d = infty
		graph.nodes[iNodes].f = infty
		graph.nodes[iNodes].parent = nil
	}
	return &graph
}

type QueueEntry struct {
	node *DirectedGraphNode
	next *QueueEntry
}

type Queue struct {
	head, tail *QueueEntry
}

func (q *Queue) enqueue(node *DirectedGraphNode) {
	entry := QueueEntry{}
	entry.node = node

	if q.tail == nil {
		q.head = &entry
		q.tail = &entry
		return
	}

	q.tail.next = &entry
	q.tail = q.tail.next
}

func (q *Queue) dequeue() *QueueEntry {
	if q.head == nil {
		return nil
	}
	poped := q.head
	q.head = q.head.next
	if q.head == nil {
		q.tail = nil
	}
	return poped
}

func (q *Queue) isEmpty() bool {
	return q.head == nil
}

var time = 0

func fillDistancesByDepthFirstSearch(g *DirectedGraph) {
	for _, u := range g.nodes[1:] {
		if !u.visited {
			dfsVisit(g, u)
		}
	}
}

func dfsVisit(g *DirectedGraph, u *DirectedGraphNode) {
	time++
	u.d = time

	u.visited = true
	for _, v := range u.adjacents {
		if !v.visited {
			v.parent = u
			dfsVisit(g, v)
		}
	}
	time++
	u.f = time
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	g := newDirectedGraph(nNodes + 1)

	for iNode := 0; iNode < nNodes; iNode++ {
		nodeKeyLeft := nodeKey(nextInt())
		nAdj := nextInt()
		for iAdj := 0; iAdj < nAdj; iAdj++ {
			nodeKeyRight := nodeKey(nextInt())
			g.setAdjacency(nodeKeyLeft, nodeKeyRight)
		}
	}

	fillDistancesByDepthFirstSearch(g)

	for iNode := 1; iNode <= nNodes; iNode++ {
		node := g.nodes[iNode]
		fmt.Println(node.key, node.d, node.f)
	}
}

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;
}