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;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

const int MAX_N = 100;
const int INF = 1e9;

int n;
int d[MAX_N], f[MAX_N];
vector<int> g[MAX_N];

int t = 1;

void dfs(int v) {
    if (d[v] == INF) d[v] = t++;
    for (auto u : g[v]) {
        if (d[u] == INF) dfs(u);
    }
    if (f[v] == INF) f[v] = t++;
}

int main() {
    fill(d, d+MAX_N, INF);
    fill(f, f+MAX_N, INF);
    cin >> n;
    for (int i = 0, u, k; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0, v; j < k; j++) {
            cin >> v;
            v--;
            g[u].push_back(v);
        }
    }
    for (int i = 0; i < n; i++) dfs(i);
    for (int i = 0; i < n; i++) {
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

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

void dfs_init();
void dfs(int u);

int n,*d,*f,time;
string *color; bool **M;

int main(){
	cin>>n;
	color = new string[n];
	M = new bool*[n]; for(int i=0;i<n;i++) M[i] = new bool[n];
	d = new int[n]; f = new int[n];

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++) M[i][j] = false;
	}

	int deg,vertex,temp;
	for(int i=0;i<n;i++){
		cin>>vertex>>deg;
		for(int j=0;j<deg;j++){
			cin>>temp;
			M[vertex-1][temp-1] = true;
		}
	}

	dfs_init();

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

	delete [] color;
	for(int i=0;i<n;i++) delete [] M[i]; delete [] M;
	delete [] d; delete [] f;
}

void dfs_init(){
	for(int i=0;i<n;i++)
		color[i] = "WHITE";
	dfs(0);
}

void dfs(int u){
	color[u] = "GRAY";
	d[u] = ++time;
	for(int v=0;v<n;v++){
		if(M[u][v] && color[v]=="WHITE")
			dfs(v);
	}
	color[u] = "BLACK";
	f[u] = ++time;
}

C++: #include <bits/stdc++.h>
using namespace std;
int d[110];
int f[110];
bool seen[110]={false};
void dfs(vector<vector<int> > &G,int &t,int v){
    seen[v] = true;
    d[v] = t;
    t++;
    for(int i=0;i<G[v].size();i++){
	int nv = G[v][i];
	if(!seen[nv]){ 
	    dfs(G,t,nv);
	}
    }
    f[v] = t;
    t++;
}
int main(void){
    int n; cin >> n;
    vector<vector<int> > G(n+1);
    for(int i=0;i<n;i++){
	int a,b;cin >> a >> b;
	for(int j=0;j<b;j++){
	    int c; cin >> c;
	    G[a].push_back(c);
	}
    }
    int t = 1;
    for(int i=1;i<=n;i++){
	if(seen[i]) continue;
	dfs(G,t,i);
    }
    for(int i=1;i<=n;i++){
	cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
	int n;
	cin>>n;
	vector<vector<int> > A(n);//????????????????????????-1?????\???????????????
	//??\???
	REP(i,n){
		int u,k;
		cin>>u>>k;
		A[i]=vector<int>(k,0);
		REP(j,k){
			int l;
			cin>>l;
			A[i][j] = l-1;
		}
	}
	//??¢?´¢
	stack<int> s;//??????????????????????????\???
	vector<int> dis(n,0);//??????????????????????????????
	vector<int> fin(n,0);//???????????????????????????
	s.push(0);//?????????0???????????????
	int time=0;
	while(!s.empty()){
	//REP(ss,3){
		int k = s.top();//??????????????????????????????
		if(dis[k]==0){
			time++;
			dis[k]=time;
			//cout<<"dis "<<k<<" / time "<<time<<endl;
		}
		bool isfinish=true;
		for(int i: A[k]){
			//cout<<"?????????"<<i<<endl;
			if(fin[i]==0){
				s.push(i);
				isfinish=false;
				break;
			}
		}
		if(isfinish){
			time++;
			fin[k]=time;
			s.pop();
			//cout<<"fin "<<k<<" / time "<<time<<endl;
		}
	}
	REP(i,n){
		cout<<i+1<<" "<<dis[i]<<" "<<fin[i]<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <iomanip>
#include <cassert>
#include <cmath>
using namespace std; typedef long long ll; ll an=0; const ll INF = 1e18; const ll MOD = 1e9+7;
typedef pair<int,int> P;
vector<int> v[100];
int ts, st[100], ed[100];

void dfs(int from) {
  if (st[from] == -1) st[from]=++ts;
  else return;
  for(int to:v[from]) {
    if (st[to] == -1) dfs(to);
  }
  if (ed[from] == -1) ed[from]=++ts; return;
}
int main(){
  int n; cin>>n;
  for(int i=0;i<n;i++) {
    int _, k; cin>>_>>k;
    for(int j=0;j<k;j++) {
      int x; cin>>x; x--;
      v[i].push_back(x);
    }
  }
  ts=0;
  fill(st, st+n, -1); fill(ed, ed+n, -1);
  for(int i=0;i<n;i++) dfs(i);
  for(int i=0;i<n;i++) {
    cout<<i+1<<" "<<st[i]<<" "<<ed[i]<<endl;
  } return 0;
}

C++: #include <iostream>

using namespace std;

int a[124][124] = {{}};
int start[124] = {};
int e[124] = {};
int c = 0;
int n;
void dfs(int k){
  if(start[k] != 0) return;
  c++;
  start[k] = c;

  for(int i = 0;i < n;i++){
    if(a[k][i] == 1){
      dfs(i);
    }
  }
  c++;
  e[k] = c;
}
int main(){

  int u,k,x;
  cin >> n;



  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> x;
      a[u - 1][x - 1] = 1;
    }
  }


  for(int i = 0;i < n;i++)  dfs(i);

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