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>

using namespace std;

#define ll long long
typedef complex<double> P;

int main() {
  int n; cin >> n;
  int adj[n][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;
      adj[u-1][v-1] = 1;
    }
  }

  int d[n] = {};
  int f[n] = {};
  int t = 1;

  stack<int> st;
  st.push(0);

  while (!st.empty()) {
    int v = st.top();

    if(d[v] == 0) {
      d[v] = t;
    }

    for (int i = 0; i < n; i++) {
      if(adj[v][i] == 1 && d[i] == 0) {
        st.push(i);
        break;
      }
    }

    if(st.top() == v) {
      f[v] = t+1;
      st.pop();
    }

    if(st.empty()) {
      t++;
      for (int i = 0; i < n; i++) {
        if(d[i] == 0) {
          st.push(i);
          break;
        }
      }
    }

    t++;
  }

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

}

C++: #include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int n,u,k,p,d[105],f[105],tt=0;
bool adm[105][105],se[105];

void makemap()
{
    memset(adm,false,sizeof(adm));
    memset(se,true,sizeof(se));
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&u,&k);
        while(k--)
        {
            scanf("%d",&p);
            adm[u][p]=true;
        }
    }
}

void dfs(int p)
{
    d[p]=++tt;
    se[p]=false;
    for(int i=1;i<=n;i++)
        if(adm[p][i]&&se[i])dfs(i);
    f[p]=++tt;
}

int main()
{
    makemap();
    for(int i=1;i<=n;i++)if(se[i])dfs(i);
    for(int i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],f[i]);
    return 0;
}

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

using namespace std;

vector<vector<int>> adjacent;
vector<pair<int, int>> ans;
vector<bool>checked;

//?????????is????????????
int dfs(int now,int time = 1) {
	ans[now].first = time;
	checked[now] = true;
	for (int i = 0; i < adjacent[now].size(); i++) {
		if (!checked[adjacent[now][i]]) {
			time = dfs(adjacent[now][i], time + 1);
		}
	}
	ans[now].second = time+1;
	return time + 1;
}

int main() {
	int n;
	cin >> n;
	adjacent = vector<vector<int>>(n);
	checked = vector<bool>(n, false);
	ans.resize(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;
			adjacent[u - 1].push_back(v-1);
		}
	}
	
	int time = dfs(0, 1)+1;
	for (int i = 0; i < n; i++) {
		if (!checked[i])time = dfs(i, time)+1;
	}
	
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
	}

}

C++: #include "bits/stdc++.h"

using namespace std;

using ll = long long;

constexpr char endl('\n');

#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define INF 100000000000ULL

vector<vector<size_t>> g;
vector<size_t> gs;
vector<size_t> gf;
stack<size_t> st;

size_t dfs(size_t i, size_t t) {
	st.push(i);
	while (!st.empty()) {
		auto j = st.top();
		vector<size_t>& l = g.at(j);
		if (gs.at(j) != 0) {
			if (gf.at(j) == 0)
				gf.at(j) = ++t;
			st.pop();
			continue;
		}
		gs.at(j) = ++t;
		for (ll k = l.size() - 1; k >= 0; --k) {
			auto n = l.at(k);
			if (gs.at(n) == 0) {
				st.push(n);
			}
		}
	}
	return t;
}

int main() {
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);

	size_t n;
	cin >> n;
	g.resize(n);
	gs.resize(n);
	gf.resize(n);

	REP(i, n) {
		size_t u, k;
		cin >> u >> k;
		u -= 1; // 0 base
		g.at(u).resize(k);
		REP(j, k) {
			cin >> g.at(u).at(j);
			g.at(u).at(j)--;
		}
	}
	size_t t = 0;
	for (;;) {
		size_t target = INF;
		REP(i, n) {
			if (gs.at(i) == 0) {
				target = i;
				break;
			}
		}
		if (target == INF) break;
		t = dfs(target, t);
	}
	
	REP(i, n) {
		cout << i + 1 << " " << gs.at(i) << " " << gf.at(i) << ::endl;
	}
	return 0;
}

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

vector<int> graph[100];
int start[100],endt[100];
int cnt;

void dfs(int num){
	start[num] = ++cnt;
	for(int i = 0;i < graph[num].size();i++){
		if(graph[num][i] != num && !start[graph[num][i]] && !endt[graph[num][i]]) dfs(graph[num][i]);
	}
	endt[num] = ++cnt;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int now,m;
		cin >> now >> m;
		for(int j = 0;j < m;j++){
			int t;
			cin >> t;
			graph[now - 1].push_back(t - 1);
		}
	}
	dfs(0);
	for(int i = 0;i < n;i++){
		if(!endt[i]) dfs(i);
	}
	for(int i = 0;i < n;i++){
		cout << i + 1 << " " << start[i] << " " << endt[i] << endl;
	}
	return 0;
}

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


class Graph {
public:
    std::vector<int> d, v;
    std::vector<std::vector<int>> arr;
    int n;
    int tp = 1;

    Graph(int n) : n(n) {
        d = std::vector<int>(n, 0);
        v = std::vector<int>(n, 0);
        arr = std::vector<std::vector<int>>(n);
    }
    
    void depth_search(int i) {
        if (d[i] == 0) {
            d[i] = tp;
            tp++;
            for (auto j : arr[i]) {
                depth_search(j - 1);
            }
            v[i] = tp;
            tp++;
        }
    }

    void print() {
        for (int i = 0; i < n; i++) {
            std::cout << i + 1 << " " << d[i] << " " << v[i] << std::endl;
        }
    }
};


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

    Graph graph(n);
    
    for (int i = 0; i < n; i++) {
        int u, k;
        std::cin >> u >> k;
        std::vector<int> vs(k);
        
        for (int i = 0; i < k; i++) {
            std::cin >> vs[i];
        }
        graph.arr[u - 1] = vs;
    }

    for (int i = 0; i < n; i++) {
        graph.depth_search(i);
    }

    graph.print();

}