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>

typedef long long ll;

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

using namespace std;

int c = 0;
vector<vector<int>> ver(100,vector<int>(100));

void dfs(int target,int *endo,int *d,int *f){
    if(endo[target]) return ;
    endo[target] = 1;
    d[target] = ++c;
    if(ver[target].empty()) {
        f[target] = ++c;
        return ;
    }
    for(auto num : ver[target]){
        dfs(num,endo,d,f);
    }
    f[target] = ++c;
}

int main(){
    int n;
    cin >> n;
    int d[n],v[n],endo[n];
    for(int i=0;i<n;i++){
        d[i] = v[i] = endo[i] = 0;
        int num,hand;
        cin >> num >> hand;
        num--;
        for(int j=0;j<hand;j++){
            int child;
            cin >> child;
            child--;
            ver[num].emplace_back(child);
        }
    }
    for(int i=0;i<n;i++) dfs(i,endo,d,v);
    for(int i=1;i<=n;i++){
        cout << i <<  " " << d[i-1] << " " << v[i-1] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int> > G;
int d[111],f[111],u[111];
void dfs(int v,int& p){
  if(u[v]) return;
  u[v]=1;
  sort(G[v].begin(),G[v].end());
  d[v]=++p;
  for(int u:G[v]) dfs(u,p);
  f[v]=++p;
}
signed main(){
  int n;
  cin>>n;
  G.resize(n,vector<int>());
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      c--;
      G[u].push_back(c);
    }
  }
  int p=0;
  for(int i=0;i<n;i++)
    if(!u[i]) dfs(i,p);
  for(int i=0;i<n;i++) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;;
  return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int v[101][101];
int k[101];
int d[101],f[101];
int n=0;
int u=0;
int t = 0;
void dfs(int l) {
	//cout << "l==" << l << endl;
	if (!d[l]) {
		d[l] = ++t;
	}
	for (int i = 0; i <= n; i++) {
		if (!d[v[l][i]]) {
			dfs(v[l][i]);
		}
	}
	f[l] = ++t;
}
int main(void) {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u;
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> v[u][j];
		}
	}
	for (int i = 0; i < n; i++) {
		f[i] = -1;
	}
	for (int i = 0; i < n; i++) {
		if (!d[i]) {
			dfs(i);
		}
	}

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

	return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const int DONE = 1;
const int YET = 0;
int fin(vector<int>a) {
	rep(i, 0, a.size()) {
		if (a[i] == YET)return i;
	}
	return -1;
}
signed main() {
	int n; cin >> n; vector<vector<int> >vec(n, vector<int>());
	rep(i, 0, n) {
		int u, k; cin >> u >> k;
		u--;
		rep(j, 0, k) {
			int v; cin >> v; v--;
			vec[u].push_back(v);
		}
	}
	vector<int>check(n, 0);
	vector<pair<int, int> >stamp(n);
	stack<int>S;
	S.push(0);
	int t = 1;
	start:
	while (!S.empty()) {
		int u = S.top();
		if (check[u] == YET) {
			stamp[u].first = t++;
			check[u] = DONE;
		}
	here:
		if (DBG) {
			cout << "t == " << t << endl;
			rep(x, 0, n) {
				cout << x + 1 << " " << stamp[x].first << " " << stamp[x].second << endl;
			}
		}
		rep(i, 0, vec[u].size()) {
			if (check[vec[u][i]] == YET) {
				S.push(vec[u][i]);
				check[vec[u][i]] = DONE;
				stamp[vec[u][i]].first = t++;
				u = vec[u][i];
				goto here;
			}
		}
		u = S.top(); S.pop();
		stamp[u].second = t++;
	}
	if (fin(check) != -1) {
		S.push(fin(check));
		goto start;
	}
	rep(i, 0, n) {
		cout << i + 1 << " " << stamp[i].first << " " << stamp[i].second << endl;;
	}

	return 0;
}