Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const MAX = 101

var f [MAX]int
var d [MAX]int
var list [][]int
var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func dfs(u, cnt int) int {
	if d[u] != 0 {
		return cnt
	}

	cnt++
	d[u] = cnt
	for _, next := range list[u] {
		cnt = dfs(next, cnt)
	}
	cnt++
	f[u] = cnt
	return cnt
}

func main() {
	n := scanInt()
	list = make([][]int, n+1)
	for i := 1; i <= n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			n := scanInt()
			list[u] = append(list[u], n)
		}
	}

	cnt := 0
	for i := 1; i <= n; i++ {
		cnt = dfs(i, cnt)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, d[i])
		fmt.Fprint(w, " ")
		fmt.Fprint(w, f[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

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

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1

using namespace std;

int adj[MAX+1][MAX+1];
int color[MAX+1],d[MAX+1],f[MAX+1];
stack<int> S;
int n;
int t=0;

int next(int u){
  for(int i=1;i<=n;i++){
    if(adj[u][i]==1&&color[i]==WHITE) return i;
  }
  return NIL;
}

void dfs(int u){
  S.push(u);
  color[u]=GRAY;
  d[u]=++t;
  while(S.empty()==false){
    u=S.top();
    int v=next(u);
    if(v!=NIL){
      color[v]=GRAY;
      d[v]=++t;
      S.push(v);
    }else{
      S.pop();
      color[u]=BLACK;
      f[u]=++t;
    }
  }
}

void dfs_init(){
  for(int i=1;i<=n;i++) color[i]=WHITE;
  dfs(1);
}

int main(){
  cin >> n;
  for(int i=1;i<=n;i++){
    int u,k; cin >> u >> k;
    for(int i=1;i<=n;i++) adj[u][i]=0;
    for(int i=0;i<k;i++){
      int v; cin >> v;
      adj[u][v]=1;
    }
  }
  dfs_init();
  for(int id=1;id<=n;id++){
    printf("%d %d %d\n",id,d[id],f[id]);
  }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)

int d[105], f[105];
bool seen[105];

void dfs(vector<vector<int> > &G, int n, int &x){
    if(seen[n]) return;
    x++;
    d[n] = x;
    seen[n] = true;

    rep(i, G[n].size()){
        int p = G[n][i];
        if(seen[p]) continue;
        dfs(G, p, x);
    }

    x++;
    f[n] = x;
}

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

    vector<vector<int> > G(n);
    rep(i, n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v;
            cin >> v;
            v--;
            G[i].push_back(v);
        }
    }

    rep(i, n){
        seen[i] = false;
    }
    int x = 0;
    rep(i, n){
        dfs(G, i, x);
    }

    rep(i, n){
        cout << i+1 << " " <<  d[i] << " " << f[i] << "\n";
    }


    return 0;
}

C++: #include<cstdio>
const char N_MAX = 105;
short time=0;
bool matrix[N_MAX][N_MAX];
char n;
struct Node{
    char state;//0:undiscovered 1:active 2:end
    short stTime, endTime;
};
Node V[N_MAX];
char next(char num){
    for(char i=0;i<n;i++){
        if(matrix[num][i]&&V[i].state==0){
            return i;
        }
    }
    return -1;
}
void dfs(char num){
    if(num==-1) return;
    V[num].stTime = ++time;
    V[num].state = 1;
    for(char i=next(num); i!=-1;i=next(num)){
        dfs(i);
    }
    V[num].state = 2;
    V[num].endTime = ++time;
}
void buildMatrix(){
	for(char i=0; i<n;i++){
		int degree, index;
		scanf("%u%u", &index, &degree);
		for(char j=0; j<degree; j++){
			int temp;
			scanf("%d", &temp);
			matrix[index-1][temp-1] = true;
		}
	}
}
int main(){
    scanf("%d", &n);
    buildMatrix();
    for(char i=0; i<N_MAX; i++){
        if(V[i].state==0){
            dfs(i);
        }
    }
    for(char i=0;i<n;i++){
        printf("%d %d %d\n", i+1, V[i].stTime, V[i].endTime);
    }
    return 0;
}

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

using namespace std;

struct Edge
{
	int to;
};

vector<vector<int>> DFS(vector<vector<Edge>>& G)
{
	int timecounter = 0;
	vector<vector<int>> result;
	result = vector<vector<int>>(2, vector<int>(G.size(), 0));
	vector<int> prev(G.size(),0);
	
	for(int i = 0; i < G.size(); i++){
		int next = i + 1;
		while(result[1][i] == 0){
			int tmp;
			if(result[0][next - 1] == 0){
				timecounter += 1;	
				result[0][next - 1] = timecounter;
			}

			if(G[next - 1].empty()){
				if(result[1][next - 1] == 0){
					timecounter += 1;
					result[1][next - 1] = timecounter;
				}
				next = prev[next - 1];
			}else{
				tmp = G[next - 1].begin()->to;
				G[next - 1].erase(G[next - 1].begin());
				prev[tmp - 1] = next;
				next = tmp;
			}
		}
	}
	return result;
}

int main(void)
{
	int n;
	cin >> n;

	vector<vector<Edge>> AdjList(n);
	for(int i = 0; i < n; i++){
		int u, k;
		cin >> u >> k;
		for(int j = 0; j < k; j++){
			int v;
			cin >> v;
			AdjList[i].push_back(Edge{v});
		}
	}

	vector<vector<int>> timestump = DFS(AdjList);
	
	for(int i = 0; i < AdjList.size(); i++){
		cout << i + 1 << " " << timestump[0][i] << " " << timestump[1][i] << endl;
	}
	return 0;
}

C++: #include <iostream>

constexpr int MAXN = 100;
int V[MAXN][MAXN];
int D[MAXN];
int F[MAXN];

template<int STACK_SIZE, typename T = int>
class Stack {

public:
    Stack() {};

    void Push(T val) {
        if (top_ < STACK_SIZE) {
            stack_[top_++] = val;
        }else{
            std::cerr << "Stack over flow..." << std::endl;
            exit(-11);
        }
    };
    bool Pop() {
        if (top_ > 0) {
            stack_[--top_];
            return true;
        }
        return false;
    };

    T Top() {
        return stack_[top_ - 1];
    }

    int Size() {return top_;}


private:
    int max_size_ = STACK_SIZE;
    int top_ = 0;
    T stack_[STACK_SIZE];
};

Stack<MAXN, int> S;

int main() {

    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        int id, e_num;
        std::cin >> id >> e_num;
        for (int j = 0; j < e_num; j++) {
            int t;
            std::cin >> t;
            V[id - 1][t - 1] = 1;
        }
    }
    int cnt = 0;
    for (int t = 0; t < n; t++) {
        if (D[t] == 0) {
            D[t] = ++cnt;
            S.Push(t);
            while (S.Size()) {
                for (int i = 0; i < n; i++) {
                    if ((V[S.Top()][i] == 1) && (D[i] == 0)) {
                        S.Push(i);
                        D[i] = ++cnt;
                        break;
                    }
                    if (i == n - 1) {
                        F[S.Top()] = ++cnt;
                        S.Pop();
                    }
                }
            }
        }
    }

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

}