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

int n;
int t = 0; //time
int d[110] = {}; //discover
int f[110]; //finish
bool a[110][110] = {}; //adjacency matrix

void dfs(int u){
  d[u] = ++t; //record the discovering time

  //if be adjoining and have not been discovered, search
  for(int i = 1;i <= n;i++) if(a[u][i] && d[i] == 0) dfs(i);
  
  f[u] = ++t; //record the finishing time
}

int main(){
  
  int u, k, v;

  //input
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> v;
      a[u][v] = true;
    }
  }

  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= n;j++){
      //if be adjoining and have not been discovered, search
      if(a[i][j] && d[i] == 0) dfs(i);
    }
  }

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

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

class Graph {
protected:
	vector< vector<int> > adjl;
public:
	Graph(int n) : adjl(n){}
	void PushAdjl(int pl, int val) { adjl[pl].push_back(val); }
};

class DFGraph : public Graph {
private:
	int t;
	vector<int> d, f;
public:
	DFGraph(int n) : Graph(n), d(n), f(n) {}
	void DepthFirstSearch(int);
	void DFSSub(int);
	void Showdf();
};

void DFGraph::DepthFirstSearch(int begin = 0) {
	t = 1;
	DFSSub(begin);
	for (int i = 0; i < d.size(); i++)
		if (d[i] == 0)
			DFSSub(i);
}

void DFGraph::DFSSub(int v) {
	d[v] = t;
	t++;
	for (auto&& i : adjl[v])
		if (d[i] == 0)
			DFSSub(i);
	f[v] = t;
	t++;
}

void DFGraph::Showdf() {
	for (int i = 0; i < d.size(); i++)
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
}

int main() {
	int n;
	cin >> n;
	DFGraph dfg(n);
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int t;
			cin >> t;
			dfg.PushAdjl(u - 1, t - 1);
		}
	}
	dfg.DepthFirstSearch();
	dfg.Showdf();
}

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){
      t=1;
      dfs(i);
    }
  }

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

  return (0);
}

C++: #include <iostream>
#include<stack>
#include<vector>
using namespace std;
int main(void){
    int n ,i,DP[1001][1001],num,p,k,f[101][3],ptr=1,v;
    stack<int> s;
        cin>>n;
    for(i=1;i<=n;i++){
        cin>>p>>k;
        for(int j=1;j<=k;j++){
            cin>> num;
            DP[i][num]=1;
        }
    }
    for(i=1;i<=n;i++){
        DP[0][i]=1;
    }
    s.push(0);
    while(!s.empty()){
        v=s.top();
        for(int i=1;i<=n;i++){
            if(DP[v][i]==1&&f[i][0]==0){
                    s.push(i);
                    f[i][0]=1;
                    f[i][1]=ptr;
                    goto Exit;
            }
        }
        s.pop();
        f[v][2]=ptr;
        Exit:;
        ptr++;
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<f[i+1][1]<<" "<<f[i+1][2]<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
int t;
vector< vector<int> > A;
vector<int> c;
vector<int> d;
vector<int> f;

void dfsVisit(int u) {
    t++;
    d[u] = t;
    c[u] = 1;
    for(int i=0; i<A[u].size(); i++) {
        int v = A[u][i];
        if(c[v] == 0) dfsVisit(v);
    }
    t++;
    f[u] = t;
}

void dfs() {
    for(int u=0; u<n; u++) c[u] = 0;
    t = 0;
    for(int u=0; u<n; u++) {
        if(c[u] == 0) {
            dfsVisit(u);
        }
    }
}

int main() {
    cin >> n;
    A.resize(n);
    c.resize(n);
    d.resize(n);
    f.resize(n);

    for(int i=0; i<n; i++) {
        int u,k;
        cin >> u >> k;
        A[u-1].resize(k);
        for(int j=0; j<k; j++) {
            int v;
            cin >> v;
            A[u-1][j] = v-1;
        }
        sort(A[u-1].begin(), A[u-1].end());
    }

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

C++: #include <iostream>

using namespace std;

int adja[101][101];
int d[101], f[101], cnt;

void dfs(int u) {
    d[u] = ++cnt;
    for (int i = 0, v; (v = adja[u][i]) > 0; ++i) {
        if (v > 0)
            continue;
        dfs(v);
    }
    f[u] = ++cnt;
}

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

    return 0;
}