Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	dfs(&g, &d, &f, 1, 1)

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

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

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

using namespace std;

struct Node {
    int visit = 0;
    vector<int> next;
    int s = 0;
    int start = 0;
    int end = 0;
};

int main() {
    int n, id, k, temp, time = 1;
    Node node[101];
    stack<int> st;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            cin >> temp;
            node[id].next.push_back(temp);
        }
    }

    while (1) {
        int s = -1;
        for (int i = 1; i <= n; i++) {
            if (node[i].visit == 0) {
                s = i;
                break;
            }
        }
        if (s == -1) {
            break;
        }
        
        node[s].start = time++;
        st.push(s);
        while (!st.empty()) {
            temp = st.top();
            if (node[temp].s < node[temp].next.size()) {
                if (node[node[temp].next[node[temp].s]].visit == 0) {
                    node[node[temp].next[node[temp].s]].start = time++;
                    node[node[temp].next[node[temp].s]].visit = 1;
                    st.push(node[temp].next[node[temp].s++]);
                }
                else {
                    node[temp].s++;
                }
            }
            else {
                node[temp].visit = 2;
                node[temp].end = time++;
                st.pop();
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << node[i].start << " " << node[i].end << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

vector<int> g[101];
bool visited[101]{};
P ans[101];

int dfs(int s, int t){
    visited[s]=true;
    ans[s].first = t;
    REP(i,g[s].size()){
        if(visited[g[s][i]])continue;
        t = dfs(g[s][i],t+1);
    }
    t++;
    ans[s].second = t;
    return t;
}


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

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

struct node {
    int start = 0;
    int end = 0;
};

void depth_search(map<int, vector<int> > &a, map<int, node> &nodes, int &time, int current) {
    time++;
    nodes[current].start = time;
    for (int i=0; i<a[current].size(); i++) {
        if ( nodes[a[current][i]].start == 0 ) {
            depth_search(a, nodes, time, a[current][i]);
        }
    }
    time++;
    nodes[current].end = time;
}

int main() {
    int n;
    cin >> n;
    map<int, vector<int> > a;
    for (int i=0; i<n; i++) {
        int u, k, v;
        cin >> u >> k;
        for (int j=0; j<k; j++) {
            cin >> v;
            a[u].push_back(v);
        }
    }
    
    int time = 0;
    map<int, node> nodes;
    for (int i=0; i<n; i++) {
        node nd; 
        nodes[i] = nd;
    }
    depth_search(a, nodes, time, 1);
    
    for (int i=1; i<=n; i++) {
        cout << i << " " << nodes[i].start << " " << nodes[i].end << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <cstdlib>

const int MAX_N = 100;

struct Node {
  int v;
  int firstVisitedTime;
  int lastVisitedTime;
  bool visited;
};

void visit(int *count, int n, std::vector<std::list<int> *> *graph, std::vector<struct Node *> *nodes) {
  (*count)++;
  
  struct Node *node = nodes->at(n);

  if (!node->visited) {
    node->firstVisitedTime = *count;
    node->visited = true;
  }  

  //  std::cout << (*count) << " = " << n << std::endl;

  std::list<int> *neighbors = graph->at(n);

  while (!neighbors->empty()) {
    int v = neighbors->front();
    neighbors->pop_front();
    
    if (!nodes->at(v)->visited) {
      visit(count, v, graph, nodes);
    }
  }

  (*count)++;
  node->lastVisitedTime = (*count);

  //  std::cout << (*count) << " = " << n << std::endl;
}

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

  int n = 0;
  std::cin >> n;

  std::vector<std::list<int> *> *graph = new std::vector<std::list<int> *>(n + 1);
  std::vector<struct Node *> *nodes = new std::vector<struct Node *>(n + 1);
  
  for (int i = 1; i <= n; i++) {
    int v = 0;
    std::cin >> v;

    int k = 0;
    std::cin >> k;

    std::list<int> *neighbors = new std::list<int>();

    for (int i = 0; i < k; i++) {
      int a = 0;
      std::cin >> a;

      neighbors->push_back(a);
    }

    graph->at(i) = neighbors;

    struct Node *node = (struct Node *) std::malloc(sizeof(struct Node));

    node->v = i;
    node->firstVisitedTime = 0;
    node->lastVisitedTime = 0;
    node->visited = false;
    
    nodes->at(i) = node;
  }

  int count = 0;
  int start = 1;

  visit(&count, start, graph, nodes);  

  for (std::vector<struct Node *>::iterator iterator = nodes->begin() + 1; iterator != nodes->end(); ++iterator) {
    struct Node *node = *iterator;
        
    std::cout << node->v << " " << node->firstVisitedTime << " " << node->lastVisitedTime << std::endl;
  }
  
  return 0;
}