Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

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

typedef vector<int> Adj_list;
typedef vector<Adj_list> Adj_lists;

class Timekeeper{
public:
  int found;
  int complete;

  Timekeeper(){
    found = 0;
    complete = 0;
  }
};
typedef vector<Timekeeper> Timekeepers;

void dfs(const int& i, const Adj_lists& adj_lists, Timekeepers& timekeepers, int& t){
  stack<int> s;
  s.push(i + 1);
  while(!s.empty()){
    // visit top of stack
    int visit = s.top();

    // if this node is not found in past, save the time.
    if(!timekeepers[visit-1].found){
      timekeepers[visit-1].found = ++t;
    }

    // find next adjecent which is not visited yet
    for(const int& adj_list : adj_lists[visit-1]){
      if(!timekeepers[adj_list-1].found){
        s.push(adj_list);
        break;
      }
    }

    // if no adj found, delete this node
    if(visit == s.top()){
      timekeepers[visit-1].complete = ++t;
      s.pop();
    }
  }
}

int main(){

  int n;
  scanf("%d", &n);

  Adj_lists adj_lists(n);
  for(int i=0; i<n; i++){
    int u, k;
    scanf("%d %d", &u, &k);
    Adj_list adj_list(k);
    for(int j=0; j<k; j++){
      int v;
      scanf("%d", &v);
      adj_list[j] = v;
    }
    sort(adj_list.begin(), adj_list.end());
    adj_lists[u-1] = adj_list;
  }

  Timekeepers timekeepers(n);
  int t = 0;
  for(int i = 0; i < n; i++){
    if(!timekeepers[i].found) dfs(i, adj_lists, timekeepers, t);
  }

  for(int i = 0; i < timekeepers.size(); i++){
    printf("%d %d %d\n", i+1, timekeepers[i].found, timekeepers[i].complete);
  }

  return 0;
}

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

int N;
int D[110];
int G[110][110];
int F[110];
int t = 1;
void dfs(int cur){
	D[cur] = t;
	t++;
	for(int i=0;i<N;i++){
		if(G[cur][i] && D[i]==0){
			dfs(i);
		}
	}
	F[cur] = t;
	t++;
}


int main(){
	while(cin >> N && N>0){
		vector<vector<int> > g(110,vector<int>(110,0));
		int u,k;
		for(int i=0;i<N;i++){
			cin >> u >> k;
			for(int j=0;j<k;j++){
				int a;
				cin >> a;
				g[u-1].push_back(a); 
			}
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<g[i].size();j++){
				int f = g[i][j];
				G[i][f-1] = 1;
			}
		}
		dfs(0);
		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;
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int n;
vector<vector<int>> adjacencyList;
enum state {New, Working, Done};
vector<state> status;
vector<int> startTime;
vector<int> endTime;
int t = 0;

vector<vector<int>> GetAdjacencyList(int n)
{
	vector<vector<int>> adjacencyList(n, vector<int>(n));
	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;
			adjacencyList[u][--v] = 1;
		}
	}
	return adjacencyList;
}

void DFS(int node)
{
	status[node] = Working;
	startTime[node] = ++t;
	for (int i = 0; i < n; i++) {
		if (adjacencyList[node][i] && status[i] == New) DFS(i);
	}
	status[node] = Done;
	endTime[node] = ++t;
}

int main()
{
	cin >> n;
	adjacencyList = GetAdjacencyList(n);
	status = vector<state>(n);
	startTime = vector<int>(n);
	endTime = vector<int>(n);
	for (int i = 0; i < n; i++) {
		if (status[i] != Done) DFS(i);
	}
	for (int i = 0; i < n; i++) cout << i + 1 << " " << startTime[i] << " " << endTime[i] << endl;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
static const int INFTY = (1 << 21);

class Edge{
public:
    int from, to, cost;
    Edge(int from = 0, int to = 0, int cost = 0) :
            from(from), to(to), cost(cost){}

    bool operator < (const Edge &e) const{
        return cost < e.cost;
    }
    bool operator >(const Edge &e) const{
        return cost > e.cost;
    }

};

class Node{
public:
    vector<Edge> edges;
    int dist;
    int done;
    int times;
    int timee;

    Node(){
        dist = INFTY;
        done = 0;
    }
};

class Graph{
public:
    vector<Node> nodes;
    Graph(int n) {
        rep(i, n) { Node n;  nodes.push_back(n); }
    }
    Node& operator[](int i){
        return nodes[i];
    }
};

class Data{

public:
    int dist;
    Edge *edge;
    Data(int dist, Edge *edge) {
        this->dist = dist;
        this->edge = edge;
    }

    bool operator < (const Data &d) const{
        return dist < d.dist;
    }
    bool operator >(const Data &d) const{
        return dist > d.dist;
    }
};

Graph G(0);

int V;
int t;

void dfs(int v){
    if (G[v].done != 0) return;

    // fprintf(stderr, "%d %d\n", v, t);

    G[v].done = 1;
    t++;
    G[v].times = t;
    for(auto &e: G[v].edges){
        dfs(e.to);
    }
    t++;
    G[v].timee = t;
}

void dfs_run(){
    t = 0;
    rep(i, V) dfs(i);
}

int main() {

    cin >> V;
    G = Graph(V);

    rep(i, V){
        int from; cin >> from; from--;
        int e_count; cin >> e_count;

        vint vec;
        rep(j, e_count){
            int to; cin >> to; to--;
            vec.push_back(to);
        }
        sort(vec.begin(), vec.end());
        rep(j, e_count){
            G[from].edges.push_back(Edge(from, vec[j], 1));
        }
    }

    dfs_run();

    rep(i, V){
        fprintf(stdout, "%d %d %d\n", i+1, G[i].times, G[i].timee);
    }
}