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

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

int main ()
{
    int N;
    cin >> N;

    int M[N][N];
    int D[N], F[N], C[N];

    for (int i = 0; i < N; i++)
    {
        D[i] = 0;
        F[i] = 0;
        C[i] = WHITE;
        
        for (int j = 0; j < N; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < N; i++)
    {
        int u, k;
        cin >> u >> k;
        u--;

        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

/*
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (j > 0)
                cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
*/
    stack<int> *S = new stack<int>;

    int time = 0;

    S->push(0);
    C[0] = GRAY;
    D[0] = ++time;

    while (S->size() > 0)
    {
        int u = S->top();
        int v = -1;

        // next 
        for (int i = 0; i < N; i++)
        {
            int flag = M[u][i];

            if (flag == 1)
            {
                if (C[i] == WHITE)
                {
                    v = i;
                    break;
                }
            }
        }

        if (v != -1)
        {
            if (C[v] == WHITE)
            {
            C[v] = GRAY;
            D[v] = ++time;
            S->push(v);
            }
        }
        else
        {
            S->pop();
            C[u] = BLACK;
            F[u] = ++time;
        }
    }

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

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


void solve(int);

typedef struct{
  int k;
  vector<int> ls;
  int f,d;
}node_t;

node_t node[101];
int t=0;

int main(){
  int n;
  int u;

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

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

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % 2019;
    } else {
        return modpow(m, n - 1) * m % 2019;
    }
}
long long n;
vector<bool> visited(100, false);
vector<int> t1(100);
vector<int> t2(100);
vector<vector<long long>> graph(100);
int ts = 1;
void dfs(int cur) {
    visited[cur] = true;
    t1[cur] = ts;
    ts++;
    for (int i = 0; i < graph[cur].size(); i++) {
        if (visited[graph[cur][i]] == false) {
            dfs(graph[cur][i]);
        }
    }
    t2[cur] = ts;
    ts++;
}
signed main() {
    cin >> n;
    for (long long i = 0; i < n; i++) {
        long long s, k;
        cin >> s >> k;
        for (int j = 0; j < k; j++) {
            int l;
            cin >> l;
            graph[s - 1].push_back(l - 1);
        }
    }
    REP(i, n) {
        if (!visited[i]) {
            dfs(i);
        }
    }
    REP(i, n) { cout << i + 1 << " " << t1[i] << " " << t2[i] << endl; }
}

C++: #include<stdio.h>
#include<stdlib.h>
#define N 102
#define white 0
#define gray 1
#define black 2

int n,color[N],d[N],f[N],S[N],top=0,t=0,nt[N],a[N][N];

void push(int x){
  if(top==N){
    printf("Stack overflow!\n");
    exit(2);
  }
  S[++top]=x;
}

int pop(void){
  if(top==0){
    printf("Stack is empty!\n");
    exit(3);
  }
  top--;
  return S[top+1];
}

int next(int u){
  int v;
  for(v=nt[u];v<=n;v++){
    nt[u]=v+1;
    if(a[u][v]) return v;
  }
  return -1;
}

void dfs(int r){
  int i;
  for(i=1;i<=n;i++) nt[i]=0;

  push(r);
  color[r]=gray;
  d[r]=++t;

  while(S[top]!=0){
    int u=S[top],v=next(u);

    if(v!=-1){
    if(color[v]==white){
      color[v]=gray;
      d[v]=++t;
      push(v);
    }
    }
    else {
      pop();
      color[u]=black;
      f[u]=++t;
    }
  }
}

void dfs_init(){
  int i,u;
  for(i=1;i<=n;i++){
    color[i]=white;
  }
  t=0;

  for(u=1;u<=n;u++){
    if(color[u]==white) dfs(u);
  }

}

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

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

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

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

  dfs_init();
  print();


  return 0;
}