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++: #define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

vector<int> G[100+1];
vector<int> d(100+1,-1);
vector<int> f(100+1,-1);
int timer= 1;

void dfs(int x){

    if(d[x]!=-1)
        return;
    d[x] = timer;
    timer++;
    for (int i = 0; i < G[x].size(); ++i) {
        dfs(G[x][i]);
    }
    f[x] = timer;
    timer++;
}

int main(void) {

    int n; cin>>n;
    for (int i = 1; i <= n; ++i) {
        int u,k; cin>>u>>k;
        for (int j = 1; j <= k; ++j) {
            int v; cin>>v;
            G[u].push_back(v);
        }
    }

    for (int i = 1; i <= n; ++i) {
        dfs(i);
    }

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

    return 0;
}

C++: #include <stdio.h>
int n,G[101][101];
int d[101];
int T = 0;
int F[101] = {0};
int k = 0;

void visit(int u) {
  int i,j,v;
  T++;  
  d[u] = T;

  for(v=0;v<n;v++) {
    if(G[u][v] == 1 && d[v] == 0 ) {
      visit(v);
    }
  }
  
  T++;
  F[u] = T;

}

int main() {
  
  
  int i,j,k,l,u,a,t;

  for(i=0;i<n;i++) d[i] = 0;

  scanf("%d",&n);

  for(i=0;i<n+1;i++)
    for(j=0;j<n+1;j++) {
      G[i][j] = 0;

    }

  for(i=0;i<n;i++){

    scanf("%d %d ",&k,&u);
    //    printf("u = %d\n",u);

    for(j=0;j<u;j++) {
      scanf("%d",&a);
      G[k -1][a-1] = 1;
      // printf("G[%d][%d] = 1\n",i,k-1);
    }
  }
  for(i=0;i<n;i++) {
    if(d[i] == 0) 
    visit (i);
  }
    
  for(i=0;i<n;i++) {
    printf("%d %d %d\n",i+1,d[i],F[i]);
  }
  return 0;

    
    
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
static const int N=100,WHITE=0,GRAY=1,BLACK=2;

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u) {
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for (v=0; v<n; v++) {
    if (M[u][v]==0) {
      continue;
    }
    if(color[v]==WHITE) {
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}
void dfs() {
  int u;
  for (u=0; u<n; u++) {
    color[u]=WHITE;
  }
  tt=0;
  for (u=0; u<n; u++) {
    if (color[u]==WHITE) {
      dfs_visit(u);
    }
  }
  for (u=0; u<n; u++) {
    cout<<u+1<<" "<<d[u]<<" "<<f[u]<<endl;
  }
}
int main() {
  int u,v,k,i,j;
  cin>>n;
  for (i=0; i<n; i++) {
    for (j=0; j<n; j++) {
      M[i][j]=0;
    }
  }
  for (i=0; i<n; i++) {
    cin>>u>>k;
    u--;
    for (j=0; j<k; j++) {
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, tt;
int M[N][N], color[N], d[N], f[N], nt[N]; 

int next(int u){
	for(int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if(M[u][v] == 1) return v;
	}
	return -1;
}

void dfs_visit(int r) {
    for(int i = 0; i < n; i++) {
        nt[i] = 0;
	}
	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;
	while(!S.empty()) {
		int u = S.top();
		int v = next(u);
		if(v != -1) {
			if(color[v] == WHITE) {
			   color[v] = GRAY;
			   d[v] = ++tt;
			   S.push(v); 	
			}
		} else {
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


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

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

C++: #include <iostream>

using namespace std;

int adja[101][101];
int stamp1[101], stamp2[101];
int n, cur = 1;

void dfs(int u) {
    stamp1[u] = cur++;
    for (int i = 1; i <= n; ++i) {
        if (adja[u][i] && stamp1[i] == 0)
            dfs(i);
    }
    stamp2[u] = cur++;
}

int main() {
    int u, k, v;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> u >> k;
        while (k--) {
            cin >> v;
            adja[u][v] = 1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (stamp1[i] == 0)
            dfs(i);
        cout << i << " " << stamp1[i] << " " << stamp2[i] << endl;
    }

    return 0;
}