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>
#define N 105
using namespace std;
int n,u,k,v,e[N][N],cnt;
int ans1[N],ans2[N];
bool used[N];
 
void dfs(int x){
  if(used[x])return;
  used[x]=true;
  ans1[x]=cnt++;
  for(int i=0;i<n;i++)
    if(e[x][i])dfs(i);
  ans2[x]=cnt++;
}
 
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      e[u-1][v-1]=1;
    }
  }
  cnt=1;
  for(int i=0;i<n;i++)
    if(!used[i])dfs(i);
  
  for(int i=0;i<n;i++)
    cout<<i+1<<' '<<ans1[i]<<' '<<ans2[i]<<endl;

  return 0;
}

C++: #include <stdio.h>
#define  MAX 100
#define FIRST 0
#define MIDDLE 1
#define END 2

int n,M[MAX][MAX];
int point[MAX],d[MAX],f[MAX],t;

void dfs_visit(int u){
    int v;
    point[u]=MIDDLE;
    d[u]=++t;
    for(v=0;v<n;v++){
        if(M[u][v]==0)continue;
        if(point[v]==FIRST){
            dfs_visit(v);
        }
    }
    point[u]=END;
    f[u]=++t;
}
void dfs(){
    int u;

    for(u=0;u<n;u++)point[u]=FIRST;
    t=0;

    for(u=0;u<n;u++){
        if(point[u]==FIRST)dfs_visit(u);
    }
    
    for(u=0;u<n;u++)printf("%d %d %d\n",u+1,d[u],f[u]);
}

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;
        }
    }
    dfs();
    
    return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X) for(long int I=X;I>=0;I--)
#define INF 1000000007
using namespace std;

int Adj[101][101];
int d[101],f[101];

int main(){
  int n,u,k,v,t=1;
  cin >> n;
  FOR(i,0,n){
    cin >> u >> k;
    FOR(j,0,k){
      cin >> v;
      Adj[u][v] = 1;
    }
  }
  stack<int> s;
  while(1){
    bool flag2 = 1;
    FOR(i,1,n+1){
      if(d[i] == 0){
        s.push(i);
        flag2 = 0;
        break;
      }
    }
    if(flag2)break;
    while(s.size()){
      if(!d[s.top()])d[s.top()] = t;
      bool flag = 0;
      FOR(i,1,n+1)if(Adj[s.top()][i] && !d[i]){
        s.push(i);
        FOR(j,1,n+1)Adj[j][i] = 0;
        flag = 1;
        break;
      }
      t++;
      if(!flag){
        f[s.top()] = t;
        s.pop();
      }
    }
    t++;
  }
  FOR(i,1,n+1)cout << i << " " << d[i] << " " << f[i] << endl;
}