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<stdio.h>

void depthfs(void);

void visit(int);

#define MAX 109

#define WHITE 0
#define GRAY 1
#define BLACK 2

int graph[MAX][MAX];

int n;
int time;
int d[MAX],f[MAX];
int color[MAX];

int main(){
  int num,i;
  int u,j,v;

  scanf("%d",&n);

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

  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&num);
    for(j=0;j<num;j++){
      scanf("%d",&v);
      graph[u][v] = 1;
    }
  }

  depthfs();

  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }

  
  return 0;

}

void depthfs(void){
  int i;
  //for each vertex u in V
  for(i=1;i<=n;i++){
  color[i] = WHITE;
  d[i] = 0;
  f[i] = 0;
  }

  time= 0;

  //for each vertex u in V
  for(i=1;i<=n;i++){
  if(color[i] == WHITE) visit(i);
  }

}

void visit(int x){
  int i;

  color[x] = GRAY;//white vertex u has just been discovered

  d[x] = ++time;

  //for each v in adj[u] //explore edge(u,v)

  for(i=1;i<=n;i++){
    if(graph[x][i] == 1){
      if(color[i] == WHITE) visit(i);
    }
  }

  color[x] = BLACK; //blacken u; it is finished

  f[x] = ++time;
  
}

C++: #include<iostream>
using namespace std;

int m[101][101];
int visit[101];
int d[101];
int f[101];
int n, t;

void dfs(int u){
  visit[u] = 1;
  d[u] = t;
  t++;
  
  for(int i = 0; i < n; ++i){
    if(m[u][i] == 1 && visit[i] == 0){
      dfs(i);
    }
  }

  f[u] = t;
  t++;
}

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

  for(int i = 0; i < n; ++i){
    if(visit[i]==0){
      dfs(i);
    }
  }

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

  return (0);
}

C++: #include <iostream>

using namespace std;

int V[100][100];
int n;

int d[100];
int f[100];

int t = 1;
void dfs(int src){
  t++;
  for(int i=1;i<=n;i++){
    if(V[src][i] != 0 && !d[i]){
      d[i] = t;
      dfs(i);
      t++;
    }
  }
  f[src] = t;
}
int main(){
  int  src, dst, num;
  cin >> n;
  for(int i=1;i<=n;i++){
    d[i] = 0; f[i] = 0;
  }
  for(int i=1;i<=n;i++){
    cin >> src >> num;
    for(int j=0;j<num;j++){
      cin >> dst;
      V[src][dst] = 1;
    }
  }
  d[1] = 1;
  dfs(1);
  for(int i=1;i<=n;i++){
    cout << i <<" "<< d[i] <<" "<< f[i] << endl;
  }
  return 0;
}

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

int n;
int common_time=1;
int g[110][110];
int d[10000];
int f[10000];

int dfs(int node){
  if(d[node]==0){
    d[node]=common_time++;
    //cout<<node<<" "<<d[node]<<"#"<<endl;
  }
  else{
    return 0;
  }
  for(int i=0;i<=n;i++){
    if(g[node][i] == 1){
      //cout<<node<<"$"<<i<<endl;
			dfs(i);
    }
  }
	f[node] = common_time++;
  //cout<<node<<" "<<f[node]<<"&"<<endl;
}

int main(){

  cin>>n;

  for(int i=0;i<n;i++){
    for (int j=0;j<n;j++){
      g[i][j]=0;
    }
  }

  for(int i=0;i<10000;i++){
    d[i]=0;
    f[i]=0;
  }
  int u;
  int k;
  int v;
  for(int i=0;i<n;i++){
    cin >>u;
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      g[u-1][v]=1;
      //g[v][u-1]=1;
    }
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      //cout<<g[i][j];
    }
    //cout<<endl;
  }
  
 for(int i=0;i<n;i++){
  dfs(i);
 }
  
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int G[101][101];
int d[101];
int f[101];
bool flag[101];
int n,v,k,p;
int t;

void check(int i){
	if(flag[i])return;
	flag[i]=true;
	t++;
	d[i]=t;
	for(int j=1;j<=n;j++){
		if(G[i][j]==1)check(j);
	}
	t++;
	f[i]=t;
	return;
}


int main(){
	cin >>n;
	for(int i=0;i<n;i++){
		cin >> v>>k;
		for(int j=0;j<k;j++){
			cin >> p;
			G[v][p]=1;
		}
	}
	t=0;
	check(1);
	for(int i=1;i<=n;i++){
		cout << i<< " "<<d[i]<< " "<<f[i] <<endl;
	}
}

C++: #include<iostream>
using namespace std;
struct T{int first,last;};
struct T ttt[200];
int n,ch[200],u,V[200][200],ti=1,a;
bool Discovery[200];
void search(int p){
    ttt[p].first=ti;ti++;
    int x;
    Discovery[p]=true;
    for(int i=1;i<=ch[p];i++){
        x=V[p][i];
        if(!Discovery[x]) search(x);
    }
    ttt[p].last=ti; ti++;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a>>ch[i];
        Discovery[i]=false;
        for(int j=1;j<=ch[i];j++){
            cin>>V[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        if(!Discovery[i]) search(i);
    }
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<ttt[i].first<<" "<<ttt[i].last<<endl;
    }
    return 0;
}