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>
#define NODE_SIZE 101

using namespace std;

struct tStamp
{
    int dsc;    //discovery
    int fin;    //finish
};

void dfs(int node, int adj[][NODE_SIZE], tStamp s[], int *cnt, int n){
    s[node].dsc = *cnt;   *cnt += 1;
    for(int i = 1; i <= n; i++){
        if(adj[node][i] && s[i].dsc == 0){
            dfs(i, adj, s, cnt, n);
        }
    }
    s[node].fin = *cnt;   *cnt += 1;
}

int main(){
    int n, u, k, v, cnt = 1;
    int adj[NODE_SIZE][NODE_SIZE] = {};
    tStamp stamp[NODE_SIZE];

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        while(k--){
            cin >> v;
            adj[u][v] = 1;
        }
    }

    for(int i = 1; i <= n; i++){
        if(stamp[i].dsc == 0){
            dfs(i, adj, stamp, &cnt, n);
        }
        cout << i << " " << stamp[i].dsc << " " << stamp[i].fin << endl;
    }

    return 0;
}

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);
    }
}