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<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> g(105);
vector<bool> visited(105);
vector<int> d(105, -1);
vector<int> f(105);

int nowTime = 0;

int dfs(int s) {
	visited[s] = true;
	nowTime++;
	if (d[s] == -1) d[s] = nowTime;

	for(auto v: g[s]) {
		if (visited[v]) continue;
		dfs(v);
	}
	
	bool ok = true;
	for (auto v: g[s]) {
		if (visited[v]) continue;
		ok = false;
	}
	if (ok) f[s] = nowTime + 1;
	return nowTime++;
}


int main(void) {
	int n;
	cin >> n;
	rep (i, n) {
		int u, k;
		cin >> u >> k;
		u--;
		rep (j, k) {
			int v;
			cin >> v;
			v--;
			g[u].pb(v);
		}
	}

	rep (i, n) if (!visited[i]) dfs(i);

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

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

static const int N = 100;
int n,color[N],M[N][N],d[N],f[N];
int t;

void dfs_visit(int u){
  int v;
  color[u] = 1;
  d[u] = ++t;
  for (v = 0; v < n; v++) {
    if(M[u][v] == 0) continue;
    if(color[v] == 0) dfs_visit(v);
  }
  color[u] = 2;
  f[u] = ++t;
}
void dfs(){
  int u;

  for (u = 0; u < n; u++) {
    color[u] = 0;
  }
  t = 0;

  for (u = 0; u < n; u++) {
    if(color[u] == 0) dfs_visit(u);
  }

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

int main() {
  int i,j,u,k,v;

  cin >> n;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }
  //cout << "done1" << endl;

  dfs();

  return 0;
}

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

int main() {
    int n;
    cin>>n;
    vector<vector<int> > arr(n);
    vector<int> tmparr;
    int u, k;
    int tmp;
    for(int i=0;i<n;++i){
        cin>>u>>k;
        u--;
        tmparr.clear();
        for(int j=0;j<k;++j){
            cin>>tmp;
            tmp--;
            tmparr.push_back(tmp);
        }
        arr[u] = tmparr;
    }
    stack<int> stack;
    stack.push(0);
    map<int, int> used;
    map<int, int> owari;
    map<int, pair<int, int> > ans;
    int state;
    int time = 1;
    while(!stack.empty()){
        while(!stack.empty()){
            state = stack.top();
            if(used[state]>0){
                if(owari[state]==0){
                    ans[state].second = time;
                    owari[state]++;
                    time++;
                }
                stack.pop();
            }
            else {
                ans[state].first = time;
                time++;
            }
            used[state]++;
            for(int i=arr[state].size()-1;i>=0;--i){
                if(used[arr[state][i]]==0){
                    stack.push(arr[state][i]);
                }
            }
        }
        for(int i=0;i<n;++i){
            if(used[i]==0){
                stack.push(i);
                break;
            }
        }
    }
    for(int i=0;i<n;++i){
        cout<<i+1<<" "<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

C++: #include <cstdio>

typedef struct vertex_{
    int found;
    int d;
    int f;
}vertex;

int search(vertex *array, int (*A)[101], int id, int n, int time){
    if(array[id].found)return time;
    array[id].found=1;
    array[id].d=++time;
    for(int i=1;i<=n;i++){
        if(A[id][i])time=search(array,A,i,n,time);
    }
    array[id].f=++time;
    return time;
}

int searchAll(vertex *array, int (*A)[101], int n){
    int time = 0;
    for(int id=1;id<=n;id++){
        if(!array[id].found){
            time=search(array,A,id,n,time);
            printf("%d\n",time);
        }
    }
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    vertex array[n+1];
    for(i=1;i<=n;i++)array[i].found=0;
    int A[101][101];
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            A[i][j]=0;
        }
    }
    for(i=1;i<=n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            A[u][v]=1;
        }
    }
    int time = searchAll(array, A, n);
    for(i=1;i<=n;i++)printf("%d %d %d\n",i,array[i].d,array[i].f);
    return 0;
}