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++: #define TST 0
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

void printM(vector<vector<int> > &vec, long height, long width){
    F(i, 0, height){
        F(j, 0, width){
            cout << vec[i][j] << space;
        }
    cout << endl;
    }
}

vector<int> seen;
vector<int> done;
int timestamp;

// Graph: グラフを表した隣接リスト
// v: 何番目のノードを訪問するのか
void dfs(vector<vector<int> > &Graph, int v){
    timestamp++;
    seen[v] = timestamp; //訪問済みにする

    // 隣接するノードを再帰的に訪問
    for(int next_v = 0; next_v < Graph[v].size();next_v++) {
        if(seen[Graph[v][next_v]] != -1) continue;
        dfs(Graph, Graph[v][next_v]);
    }
    // 出るときの時間が増える
    timestamp++;
    done[v] = timestamp; // 隣接ノードを全て調べ終えた
}

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int u;
    int k;
    vector<vector<int> > Graph;
    cin >> u;
    int id;
    F(i, 0, u){
        cin >> id;
        cin >> k;
        vector<int> list = vector<int>(k);
        F(j, 0, k){
            cin >> list[j];
            list[j]--;
        }
        Graph.pb(list);
    }
    seen.assign(u, -1);
    done.assign(u, -1);
    timestamp = 0;

    F(i, 0, u){
        if(seen[i] == -1)dfs(Graph, i);
    }
    F(i, 0, u){
        cout << i+1 << space << seen[i] << space << done[i] << endl;
    }
#if TST==1
#endif
}

C++: #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
 
int d[111], f[111];
bool visited[111];
vector<vector<int> > g(111);
int t;
void dfs(int x){
  t++;
  d[x] = t;
  visited[x] = true;
  for(auto &u : g[x]){
    if(!visited[u]){
      dfs(u);
    }
  }
  t++;
  f[x] = t;
}
 
int main(){
  int n; cin >> n;
  FOR(i,0,n){
    int u, k; cin >> u >> k;
    FOR(j,0,k){
      int v;
      cin >> v;
      g[u].push_back(v);
    }
  }
  FOR(i,0,n+1) visited[i] = false;
  t = 0;
  FOR(i,1,n+1){
    if(!visited[i]) dfs(i);
  }
 
  FOR(i,1,n+1){
    printf("%d %d %d\n", i, d[i], f[i]);
  }
  return 0;
}

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

using namespace std; 

int Time;
vector< vector<int> > adj;
vector< pair<int,int> > res;

void dfs(int v) {
	res[v].first = Time;
	for (int i = 0; i < adj[v].size(); ++i) {
		if (res[adj[v][i]].first < 0) {
			++Time;
			dfs(adj[v][i]);
		}
	}
	++Time;
	res[v].second = Time;
	return;
}

int main(void) {
	int nov,noe,u,v;
	cin >> nov;
	adj = vector< vector<int> >(nov);
	for (int i = 0; i < nov; ++i) {
		cin >> u;
		cin >> noe;
		adj[u-1] = vector<int>(noe);
		for (int j = 0; j < noe; ++j) {
			cin >> adj[u-1][j];
			--adj[u-1][j];
		}
	}
	Time = 1;
	res = vector< pair<int,int> >(nov,{-1,-1});
	int start = 0;
	while (start >= 0) {
		dfs(start);
		start = -1;
		++Time;
		for (int i = 0; start < 0 && i < nov; ++i) {
			if (res[i].first < 0) {
				start = i;
			}
		}
	}
	for (int i = 0; i < nov; ++i) {
		cout << i+1 << " ";
		cout << res[i].first << " ";
		cout << res[i].second << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int v[101][101];
int node[101][2];
int t=1;
int n;
void dfs(int i){
   
    node[i][0]=t;
    t++;
    for(int i=1;i<=n;i++){
        v[i][1]=0;
    }
    for(int j=1;j<=n;j++){
        if(v[i][j]==1){
            for(int k=1;k<=n;k++){
                v[k][j]=0;
            }
            dfs(j);
        }
    }
    node[i][1]=t;
    t++;
}
int main(void){
    
    cin >> n;
    int x,y,z;
    for(int i=1;i<=n;i++){
        cin >> x>>y;
        for(int j=1;j<=y;j++){
            cin >> z;
            v[i][z]=1;
        }
    }
    dfs(1);
    
   for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(v[i][j]==1){
                dfs(i);
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout <<i<< " " <<node[i][0]<<" " <<node[i][1]<<endl;
    }
   
    
}