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>
using namespace std;

int n;
int k;
int color[100];
int a[100],b[100],c;
int adj[110][110];

void deepread(int k){
  int h;
  color[k]=1;
  a[k]=++c;
  for(h=0;h<n;h++){
    if(adj[k][h]==0){
      continue;
    }
    if(color[h]==0){
      deepread(h);
    }
  }
  color[k]=3;
  b[k]=++c;
}

void deep(){
  for(int i=0;i<n;i++){
    color[i]=0;
  }
  c=0;
  for(int k=0;k<n;k++){
    if(color[k]==0)deepread(k);
  }
  for(int k=0;k<n;k++){
    cout<<k+1<<" "<<a[k]<<" "<<b[k]<<endl;
  }
}


int main(){
  int num;
  cin>>n;
  int rin;
  int i=0,j=0;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      adj[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    cin>>num>>k;
    num--;
    for(j=0;j<k;j++){
      cin>>rin;
      rin--;
      adj[num][rin]=1;
    }
  }
  /*for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j)cout<<" ";
      cout<<adj[i][j];
    }
    cout<<endl;
    }*/

  deep();
  return 0;
}

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

int t=0,k,n;
int gone[100+10]={},a[100+10][100+10]={},d[200+10],f[200+10];

void dfs(int cur){
    if(gone[cur]!=1){
        t+=1;
        d[cur]=t;
        gone[cur]=1;
    }
    for(int m=1;m<=n;m++){
        if(a[cur][m]==1){
            if(gone[m]==0){
                dfs(m);
            }
        }
    }
    t+=1;
    f[cur]=t;
}

int main(){
    cin >> n;
    for(int i=1;i<=n;i++){
        int u,p;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            cin >> p;
            a[i][p]=1;
        }
    }
    for(int q=1;q<=n;q++){
        if(gone[q]!=1) dfs(q);
    }
    for(int r=1;r<=n;r++){
        cout << r << " " << d[r] << " " << f[r] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int a[105][105];
pair<int,int> ans[105];
int co;
int n;
void dfs(int x){
  if(ans[x].first==0){
    co++;
    ans[x].first = co ;
  }
  //cout << n << endl;
  for(int i=0;i<n;i++){
    //cout << a[x][i]<<endl;
    if(a[x][i]==1)dfs(i);
  }
  if(ans[x].second==0){
    co++;
    ans[x].second=co;
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    int u,m;
    cin >> u >> m;
    for(int j=0;j<m;j++){
      int v;
      cin >> v;
      a[u-1][v-1]=1;
    }
  }
  dfs(0);
  for(int i=0;i<n;i++){
    cout << i+1 << " " << ans[i].first << " "<< ans[i].second << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<stack>

#define Max 100
#define white 0
#define gray 1
#define black 2
using namespace std;
int dia=0;
int d[Max+1],f[Max+1];
	bool g[Max+1][Max+1];
	int color[Max+1];
	
void dft(int a,int n){
	int i;
	color[a]=gray;
	d[a]=++dia;
	for(i=1;i<=n;i++){
		if(g[a][i] && color[i]==white)
			dft(i,n);	
		}
		color[a]=black;
		f[a]=++dia;
	
}
void defa( int n){
	int i;
	for( i=1;i<=n;i++)
	color[i]=white;
	for(i=1;i<=n;i++){
		if(color[i]==white)
		dft(i,n);
	}
}
main(){
	int j,i,n,u,k,v;
	
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++)
		g[i][j]=false;
	}
	for(i=1;i<=n;i++){
		scanf("%d%d",&u,&k);
		for(j=0;j<k;j++){
		scanf("%d",&v);
		g[u][v]=true;
		}
	}
	defa(n);
	for(i=1;i<=n;i++)
	printf("%d %d %d\n",i,d[i],f[i]);
	
	return 0;
}

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

int r[101][101];
int d[101], f[101], num, visit[100]={0}, p=0;

void dfs(int n){
    if(!visit[n]){
        visit[n]++;
        d[n] = ++p;
        for(int i=1; i<num+1; i++)
            if(r[n][i]) dfs(i);
        f[n] = ++p;
    }
}

int main(void){
    int u, k, v;
    cin >> num;
    for(int i=0; i<num; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v;
            r[u][v]++;
        }
    }
    for(int i=1; i<num+1; i++){
        if(!visit[i]) dfs(i);
    }
    for(int i=1; i<num+1; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
}

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

void InputSet(std::vector<int> & a) {
	int n;
	cin >> n;
	a.resize(n,0);
	for(int i=0;i<n;++i) {
		cin >> a.at(i);
		a.at(i)--;
	}
}
void DFS(vector<vector<int> > & Ad,
		 vector<int> & D,
		 vector<int> & F,
		 int & time,
		 int idx)
{
	if (F[idx] < 0) {
		for(int i=0;i<(int)Ad[idx].size();++i) {
			int next = Ad[idx][i];
			if (D[next] < 0) {
				D[next] = time++;
				DFS(Ad,D,F,time,next);
			}
		}
		F[idx]= time++;
	}
}
int main(){
	int n;
	cin >> n;
	vector<vector<int> > Ad(n);
	vector<int> D(n,-1),F(n,-1);
	for(int k=0;k<n;++k) {
		int u;
		cin >> u;
		--u;
		InputSet(Ad[u]);
	}
	int time=1;
	for(int i=0;i<n;++i) {
		if (D[i] < 0) {
			D[i] = time++;
			DFS(Ad,D,F,time,i);
		}
	}

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