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<cstdio>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define 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++) {
		printf("%d %d %d\n", u + 1, d[u], f[u]);
	}
}
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++: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <climits>
#include <stack>

using namespace std;

int main() {
	stack<int> S;

	int n;
	int u, v;
	int AdjList[101][99];
	int next[101];
	int Deg[101];
	bool Visited[101];
	int d[101], f[101], time;
	int i, j;
	cin >> n;
	for (i = 1; i <= n; i++) {
		Visited[i] = false;
		next[i] = 0;
		d[i] = 0;
		cin >> u;
		cin >> Deg[u];
		for (j = 0; j < Deg[u]; j++) {
			cin >> v;
			AdjList[u][j] = v;
		}
	}

	time = 1;
	v = 1;
	S.push(v);
	while (S.empty() != true) {
		v = S.top();
		if (d[v] == 0) {
			d[v] = time++;
		}
		Visited[v] = true;
		for (i = next[v]; i < Deg[v]; i++) {
			u = AdjList[v][i];
			if (Visited[u] != true) {
				S.push(u);
				break;
			}
		}
		if (i == Deg[v]) {
			S.pop();
			f[v] = time++;
		}
		else {
			next[v] = i + 1;
		}
	}

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

	return 0;

}

C++: #include <iostream>
#include <vector>
#include <functional>

using namespace std;

template <class T>
struct Edge {
    int to;
    T cost;
    Edge(int to, T cost) : to(to), cost(cost){};
};

template <class T = int>
class Graph {
public:
    explicit Graph(int N = 0) : size(N) { path.resize(size); }
    void span(int u, int v, T cost = 1) { path[u].push_back(Edge<T>(v, cost)); }
    vector<Edge<T>> operator[](int v) const { return path[v]; }

    int size;
    vector<vector<Edge<T>>> path;
};

int main() {
    int N;
    cin >> N;
    Graph<> graph(N);
    for (int i = 0; i < N; ++i) {
        int v, k;
        cin >> v >> k;
        --v;
        for (int j = 0; j < k; ++j) {
            int sv;
            cin >> sv;
            graph.span(v, --sv);
        }
    }

    vector<int> d(N, -1), f(N, -1);
    function<int(int, int)> dfs = [&](int v, int t) -> int {
        d[v] = t;
        for (auto e : graph[v]) {
            if (d[e.to] < 0) t = dfs(e.to, t + 1);
        }
        return f[v] = ++t;
    };

    int t = 0;
    for (int v = 0; v < N; ++v) {
        if (d[v] < 0) t = dfs(v, t + 1);
    }

    for (int v = 0; v < N; ++v) {
        cout << v + 1 << " " << d[v] << " " << f[v] << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ")
#define pdd(a,n,m)for(int i=0;i<m;i++)pd(a,m)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

int n;
vector<int>G[1111];
int d[111];
int f[111];
int cnt;

void dfs(int x){

  d[x]=++cnt;

  rep(i,G[x].size()){
    int to=G[x][i];
    if(d[to]==0)
      dfs(to);
  }
  f[x]=++cnt;
}

int main(){
  cin>>n;
  rep(i,n){
    int k,s;
    cin>>k>>s;
    rep(j,s){
      int to;
      cin>>to;
      G[k].pb(to);
    }
    sort(G[k].begin(),G[k].end());
  }

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

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

  return 0;
}

C++: #include <iostream>
using namespace std;
int t = 1;
int d[100], f[100];
int a[100][100];
int N;
void dfs(int cur) {
 d[cur] = t;
 t++;
 for (int i=0; i<N; i++) {
  if (a[cur][i] == 1 && d[i] == 0) {
   dfs(i);
  }
 }
 f[cur] = t;
 t++;
}

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