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 <iostream>
#include <vector>
#include <list>
#include <cstdlib>

const int MAX_N = 100;

struct Node {
  int v;
  int firstVisitedTime;
  int lastVisitedTime;
  bool visited;
  bool opened;
};

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

  int n = 0;
  std::cin >> n;

  std::vector<std::list<int> *> *graph = new std::vector<std::list<int> *>(n + 1);
  std::vector<struct Node *> *nodes = new std::vector<struct Node *>(n + 1);
  
  for (int i = 1; i <= n; i++) {
    int v = 0;
    std::cin >> v;

    int k = 0;
    std::cin >> k;

    std::list<int> *neighbors = new std::list<int>();

    for (int j = 0; j < k; j++) {
      int a = 0;
      std::cin >> a;

      neighbors->push_back(a);
    }

    graph->at(i) = neighbors;

    struct Node *node = (struct Node *) std::malloc(sizeof(struct Node));

    node->v = i;
    node->firstVisitedTime = 0;
    node->lastVisitedTime = 0;
    node->visited = false;
    node->opened = false;
    
    nodes->at(i) = node;
  }
  
  std::list<int> *stack = new std::list<int>();

  int start = 1;
  
  stack->push_front(start);
  
  nodes->at(start)->firstVisitedTime = 1;
  nodes->at(start)->lastVisitedTime = 1;

  int count = 0;

  while (!stack->empty()) {
    count++;
    
    int n = stack->front();
    struct Node *node = nodes->at(n);

    if ((node->visited) && (!node->opened)) {
      count--;
    }
    
    if (!node->visited) {
      node->firstVisitedTime = count;
      node->visited = true;
    }
    
    //std::cout << count << " = " << n << std::endl;
    
    if (node->opened) {
      node->lastVisitedTime = count;
       
      stack->pop_front();
      
      continue;
    }
    
    std::list<int> *neighbors = graph->at(n);

    while (!neighbors->empty()) {
      int v = neighbors->front();
      neighbors->pop_front();

      if (!nodes->at(v)->visited) {
	stack->push_front(v);

	break;
      }
    }

    if (neighbors->empty()) {
      node->opened = true;
    }
  }

  for (std::vector<struct Node *>::iterator iterator = nodes->begin() + 1; iterator != nodes->end(); ++iterator) {
    struct Node *node = *iterator;
        
    std::cout << node->v << " " << node->firstVisitedTime << " " << node->lastVisitedTime << std::endl;
  }
  
  return 0;
}

C++: #include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
void depth_search(int);
void depth();
int n,M[N][N];
int color[N],d[N],f[N],t;
int main(){

  int u,v,k,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)
      M[i][j]=0;


  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
      
    }
  }
  depth();
  return 0;

}
void depth_search(int u){
  int v;
  color[u]=GRAY;
  d[u]=++t;
for(v=0;v<n;v++){
  if(M[u][v]==0)
    continue;
  if(color[v]==WHITE){
    depth_search(v);}
 }
 color[u]=BLACK;
 f[u]=++t;
}
void depth(){
  int u;

  for(u=0;u<n;u++)color[u]=WHITE;
  t=0;
  for(u=0;u<n;u++){
    if(color[u]==WHITE)
      depth_search(u);
  }
  for(u=0;u<n;u++){

    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
  }

C++: #include<stdio.h>
 
#define MAX 101
#define BLACK 0
#define WHITE 2
#define GRAY 1


int f[MAX];
int c=0;
int col[MAX];
int depth[MAX];



int dfs[MAX][MAX];
int k[MAX];



void dfsvisit(int u)
{
  int i;
  col[u] = GRAY;
 


depth[u] =  c++;
  for(i = 0;i < k[u]; i++)
    {
      if(col[dfs[u][i]] == WHITE)
    {
     

      dfsvisit(dfs[u][i]);
   

    }
    }
  col[u] = BLACK;
  f[u] = c++;
}

 







int main(){
int n,i=0;
  
 
 
  for(i=0;i<101;i++)
    {
      col[i] = WHITE;
} 




int j;
int tmp;
 
  scanf("%d",&n);
 
  for(i=1;i<=n;i++)
    {
      scanf("%d",&tmp);

      scanf("%d",&k[i]);

      for(j = 0;j < k[i]; j++)
    {
      scanf("%d",&dfs[i][j]);
    }
    }
  
  for(i = 1;i <= n; i++){
      if(col[i] == WHITE){
     

dfsvisit(i);
    }
    }
  for(j = 1;j <= n; j++)
    {
      /*出力が合わないので補正*/
      printf("%d %d %d\n",j,depth[j]+1,f[j]+1);
    }
 
  return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int a[101][101],start[101],end[101],n,p=0,v[101];
void dfs(int u){
	if(!v[u]){v[u]++;
	start[u]=++p;
	r(i,1,n+1)if(a[u][i])dfs(i);
	end[u]=++p;}
}
int main(){
	int q,qq,qqq;
	cin>>n;
	r(i,0,n){cin>>q>>qq;
		r(i,0,qq){cin>>qqq;
			a[q][qqq]++;
		}
	}
	r(i,1,n+1)if(!v[i])dfs(1);
	r(i,1,n+1)cout<<i<<' '<<start[i]<<' '<<end[i]<<endl;
}