Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) doesAllAdjsVisited(vertices []vertex) bool {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return false
		}
	}
	return true
}

func (v *vertex) isFirstVisit() bool {
	return v.firstVisitAt == 0
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func (v *vertex) nextVertex(vertices []vertex) (vertexId, error) {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return vId, nil
		}
	}
	return vertexId(-1), fmt.Errorf("illegal")
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	timestamp = timestamp + 1
	currentVertex := &vertices[currentId-1]
	if currentVertex.isFirstVisit() {
		currentVertex.firstVisitAt = timestamp
	}
	for !currentVertex.doesAllAdjsVisited(vertices) {
		nextVertexId, _ := currentVertex.nextVertex(vertices)
		timestamp = dfs(nextVertexId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	dfs(vertexId(1), 0, vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

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;
        }
    }
    S.Push(0);

    int cnt = 1;
    D[0] = cnt;
    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;
    }

}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

int ad_num[110];
vector<int> ad[110];
int t=0;
int d[110];
int f[110];

void dfs(int v){
    t++;
    if(d[v]==-1) d[v]=t;
    //if(ad_num[v]==0) return;
    for(auto e: ad[v]){
        //t++;
        if(d[e]==-1) dfs(e);
    }
    t++;
    if(f[v]==-1) f[v]=t;
}

void solve(){

    int n;
    cin >> n;
    rep(i,n){
        int trash;
        cin >> trash;
        cin >> ad_num[i];
        rep(j,ad_num[i]){
            int tmp;
            cin >> tmp;
            tmp--;
            ad[i].emplace_back(tmp);
        }
    }
    rep(i,n){
        d[i]=-1;
        f[i]=-1;
    }
    dfs(0);
    rep(i,n){
        if(d[i]==-1) dfs(i);
    }

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

}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

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

using namespace std;

int main(){
    stack<int> st;
    int n;
    cin >> n;
    int d[n] = {};
    int f[n] = {};
    int vnum[n][2] = {};
    bool vflag[n] = {};
    int tmp2;
    int num;
    vector<vector<int>> vertex;
    vector<int> tmp;
    for(int i=0;i<n;i++){
        cin >> num;
        cin >> num;
        vnum[i][0] = num;
        for(int j=0;j<num;j++){
            cin >> tmp2;
            tmp.push_back(tmp2);
        }
        vertex.push_back(tmp);
        tmp.clear();
    }
    int cnt = 1;
    bool check;
    int s;
    st.push(0);
    do{
        s = st.top();

        if(f[s]==0){
            if(((vnum[s][0]==0) && d[s]==0) || (s==vertex[s][vnum[s][1]]-1)){
                vflag[s] = true;
                d[s] = cnt++;
                f[s] = cnt++;
                st.pop();
            }else if((vflag[vertex[s][vnum[s][1]]-1]) && (d[s]==0)){
                if(vnum[s][0]-vnum[s][1]==1){
                    vflag[s] = true;
                    d[s] = cnt++;
                    f[s] = cnt++;
                    st.pop();
                }else{
                    vnum[s][1]++;
                }
            }else if(vflag[vertex[s][vnum[s][1]]-1]){
                vflag[s] = true;
                f[s] = cnt++;
                st.pop();
            }else if(vflag[s]){
                vflag[s] = true;
                f[s] = cnt++;
                st.pop();
            }else{
                if(d[s]==0){
                    d[s] = cnt++;
                }
                st.push(vertex[s][vnum[s][1]++] - 1);
                if(vnum[s][0]==vnum[s][1]){
                    vflag[s] = true;
                }
                if(vflag[vertex[s][vnum[s][1]]-1]){
                    f[s] = cnt++;
                    st.pop();
                }
            }
        }else{
            st.pop();
        }
        check = !st.empty();
        if(!check){
            for(int i=0;i<n;i++){
                if(vflag[i]==false){
                    check = true;
                    st.push(i);
                    break;
                }
            }
        }
    }while(check);

    for(int i=0;i<n;i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}