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 <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int N;
int tt = 0;
vector< vector<int> > G;
vector<int> H, d, f;
int itrNum[100001];
stack<int> S;

void dfs(int u){
    S.push(u);
    H[u] = 0;

    while(!S.empty()){
        u = S.top();  // ?¨????????????????
        if(d[u] == 0) d[u] = ++tt;
        auto itr_v = next(G[u].begin(), itrNum[u]);
        if(itr_v != G[u].end()){
            itrNum[u]++;
            int v = *itr_v;
            if(H[v] == -1){
                H[v] = 0;
                S.push(v);
            }
        }else{
            S.pop();
            H[u] = 1;
            f[u] = ++tt;
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    G = vector<vector<int> >(N);
    H = vector<int>(N, -1);
    d = vector<int>(N, 0);
    f = vector<int>(N, 0);
    memset(itrNum, 0, sizeof(itrNum));
    REP(i, N){
        int u,k;
        cin >> u >> k;
        u--;
        REP(j ,k){
            int v;
            cin >> v;
            v--;
            G[u].pb(v);
        }
    }

    REP(i, N) if(H[i] == -1) dfs(i);
    REP(i, N){
        cout << i+1 << " " << d[i] << " " << f[i] << "\n";
    }
    return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
#define MAX 100
#define WHITE 1
#define GRAY 2
#define BLACK 3

int n;
int graph[MAX][MAX];
stack<int> st;
int *d,*f,*v;
int *color;
int tm = 0;

int next(int k){
	for(int i = v[k];i < n;i++){
		v[k]++;
		if(color[i] == WHITE && graph[k][i] == 1) return i;
	}
	return -1;
}

void dfs(int k){
	for(int i = 0;i < n;i++) v[i] = 0;

	st.push(k);
	d[k] = ++tm;
	color[k] = GRAY;

	while(!st.empty()){
		int m = next(st.top());
		if(m != -1){
		  if(color[m] == WHITE){
				st.push(m);
				color[m] = GRAY;
				d[m] = ++tm;
			}
		}else{
			f[st.top()] = ++tm;
			color[st.top()] = BLACK;
			st.pop();
		}
	}
}


int main(){
	cin >> n;
	//?????????
	color = new int[n];
	d = new int[n];
	f = new int[n];
	v = new int[n];
	for(int i = 0;i < n;i++){
		color[i] = WHITE;
		d[i] = 0;
		f[i] = 0;
		for(int j = 0;j < n;j++){
			graph[i][j] = 0;
		}
	}
	//data input
	for(int i = 0;i < n;i++){

		int t,k,p;

		cin >> t >>  k;
		for(int j = 0;j < k;j++){
			cin >> p;
			p--;
			graph[i][p] = 1;
		}
	}
	for(int i = 0;i < n;i++){if(color[i] == WHITE) dfs(i);}
	for(int i = 0;i < n;i++){
		cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

C++: #include<iostream>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
using namespace std;
int G[100][100] = {};
int time = 0;
typedef struct ANS
{
	int id, t, e;
	bool done;
};

void rec(ANS a[],int t)
{
	::time++;
	a[t].t = ::time;
	a[t].done = true;
	FOR(i, 0, 100)
	{
		if (G[t][i] == 1 && a[i].done == false)
		{
			rec(a, i);
		}
	}
	::time++;
	a[t].e = ::time;
}

int main()
{
	ANS ans[101];
	int n;
	cin >> n;
	FOR(i, 0, n)
	{
		ans[i].id = i + 1;
		ans[i].done = false;
		int u, m;
		cin >> u >> m;
		FOR(j, 0, m)
		{
			int l;
			cin >> l;
			G[u - 1][l - 1] = 1;
		}
	}
	rec(ans, 0);
	FOR(i, 0, n)
	{
		cout << ans[i].id << " " << ans[i].t << " " << ans[i].e << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int visit[101],d[101],f[101],t;
int n,M[101][101];

static const int WHITE=0;
static const int GRAY=1;

void dfs(int u){
  visit[u]=GRAY;
  d[u]=++t;
  for(int v=0;v<n;v++){
    if(M[u][v]==0) continue;
    if(visit[v]==WHITE){
      dfs(v);
    }
  }
  f[u]=++t; 
}

int main(){
  int u,v,k;
  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]==WHITE){
      dfs(i);
    }
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
}

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

stack<int> S;
int n, x[10000][10000], a, b, c, d, _time=2;
int y[10000][3];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> b >> c;
		for (int j = 1; j <= c; j++) {
			cin >> d;
			x[i][d] = 1;
		}
	}
	S.push(1);
	y[1][1] = 1;
	while (!S.empty()) {
		a = S.top();
		for (int i = 1; i <= n; i++) {
			if (x[a][i] == 1 && y[i][0] == 0) {
				y[i][0] = 1;
				y[i][1] = _time;
				S.push(i);
				goto Exit;
			}
		}
		S.pop();
		y[a][2] = _time;
	Exit:;
		_time++;
	}
	for (int i = 1; i <= n; i++) {
		cout << i << ' ' << y[i][1] << ' ' << y[i][2] << endl;
	}
	return 0;
}