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>
#include <stack>
#include <vector>

using namespace std;

int n;
int V[105][105];
vector<int> d(105, 0), f(105, 0);
int t = 0;

void dfs(int x) {
	bool p = false;
	if (d[x] != 0) p = true;
	if (d[x] == 0) {
		t++;
		d[x] = t;
	}
	for (int j = 1; j <= n; j++) {
		if (V[x - 1][j - 1] == 1 && d[j] == 0) {
			dfs(j);
		}
	}
	t++;
	if (p) t--;
	if (f[x] == 0) f[x] = t;
}


int main() {
	cin >> n;
	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			V[i][j] = 0;
		}
	}
	for (int i = 0; i<n; i++) {
		int p, m;
		cin >> p >> m;
		for (int j = 0; j<m; j++) {
			int q;
			cin >> q;
			V[p - 1][q - 1] = 1;
		}
	}
	for (int i = 0; i<n; i++) {
		dfs(i + 1);
	}
	for (int i = 0; i<n; i++) {
		cout << i + 1 << " " << d[i + 1] << " " << f[i + 1] << endl;
	}
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef int ll;
typedef pair<ll, ll> P;

ll N = 100;
vector<ll> ans1;
vector<ll> ans2;
vector<bool> seen;
ll C = 0;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}


void dfs(vector< vector<ll> > &G, int v) {
  seen[v] = true;
  // v から行ける各頂点 next_v について
  for (auto next_v : G[v]) {
    if (seen[next_v]) continue; // next_v が探索済だったらスルー
    ans1[next_v] = ++C;
    //printf("ans1[%d] = %d\n", next_v+1, C);
    dfs(G, next_v); // 再帰的に探索
    ans2[next_v] = ++C;
    //printf("ans2[%d] = %d\n", next_v+1, C);
  }
}

int main() {
  cin >> N;
  vector< vector<ll> > G(N);
  G.resize(N);
  seen.resize(N, false);
  ans1.resize(N, 0);
  ans2.resize(N, 0);
  int k;
  int tmp;
  rep(i, N) {
    cin >> tmp >> k;
    rep(j, k) {
      int tmp;
      cin >> tmp;
      G[i].push_back(tmp-1);
    }
  }

  rep(i, N) {
    if (!seen[i]) {
      ans1[i] = ++C;
      dfs(G, i);
      ans2[i] = ++C;
    }
  }
  rep(i, N) {
    cout << i+1 << " " << ans1[i] << " " << ans2[i] << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
struct Node{
  int u;
  int k;
  int v[99];

  int start;
  int finish;
};

int deep(Node nod[],int x,int count){
  if(nod[x].start)
    return count;

  nod[x].start=(++count);
  for(int i=0; i<nod[x].k; i++)
    count = deep(nod,nod[x].v[i]-1,count);

  nod[x].finish= (++count);
  return count;
}

int main(){
  int n,count=0;
  Node nod[100];

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> nod[i].u >> nod[i].k;
    
    for(int j=0; j<nod[i].k; j++)
      cin >> nod[i].v[j];
    
    nod[i].start=0;
    nod[i].finish=0;
  }

  for(int i=0; i<n; i++)
    count = deep(nod,i,count);
  
  for(int i=0; i<n; i++){
    cout << nod[i].u << " " << nod[i].start << " " << nod[i].finish << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

int find_t[101],end_t[101];
int lft[101],rht[101];
int flag[101];
int t=1;

void DFS(int);
void Print();

int main(int argc,char* argv[]){
  int n,id,cnt,x,head=0;
  
  memset(find_t,0,sizeof(find_t));
  memset(end_t,0,sizeof(end_t));
  memset(lft,255,sizeof(lft));
  memset(rht,255,sizeof(rht));
  memset(flag,0,sizeof(flag));

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>id>>cnt;
    for(int l=0;l<cnt;l++){
      cin>>x;
      flag[x]=1;
      (l==0) ? lft[id]=x : rht[id]=x;
    }
  }

  for(int i=1;i<=n;i++){
    if(flag[i]==0){
      head=i;
      break;
    }
  }

  memset(flag,0,sizeof(flag));
  DFS(head);
  Print();
  
  return 0;
}

void DFS(int p){
  if(flag[p]==0){
    find_t[p]=t++;
    flag[p]=1;
  }
  else
    return;
    
  if(lft[p]!=-1)
    DFS(lft[p]);
  if(rht[p]!=-1)
    DFS(rht[p]);

  end_t[p]=t++;
}

void Print(){
  for(int i=1;i<=100;i++){
    if(find_t[i]!=0)
      printf("%d %d %d\n",i,find_t[i],end_t[i]);
  }
}

C++: #include<stdio.h>
#define MAX 102
#define WHITE 0
#define BLACK 1
#define GRAY 2


void init();
void visit(int);

int col[MAX];
int n, t = 0;
int d[MAX],f[MAX],edge[MAX],num[MAX][MAX],G[MAX][MAX];

void init(){

  int i,j;

  for(i = 0; i <= n; i++){
      col[i] = WHITE;
    }

}

void dFSearch(){
  int i;
  for(i = 1; i <= n; i++){
    if(col[i] == WHITE) visit(i);
  }
}

void visit(int u){
  int i,j;

  col[u] = GRAY;
  t += 1;
  d[u] = t;

  for(j = 0; j < n; j++){
    if(G[u][j] == 10) {
      if(col[j+1] == WHITE ){
    visit(j+1);
      }
    }
  }

  col[u] = BLACK;
  t = t + 1;
  f[u] = t;

}


int main(){

  int i,j,k = 0,vertex,number;

  scanf("%d\n",&n);
  init();

  for(i = 1; i <= n; i++){
    scanf("%d %d",&vertex,&edge[i]);
    for(j = 1; j <= edge[i]; j++){
      scanf("%d",&number);
      G[vertex][number-1] = 10;
    }
    scanf("\n");
  }

 dFSearch();

  for(i = 1; i <= n; i++){
    printf("%d %d %d\n", i, d[i], f[i]);
  }

  return 0;


}

C++: #include <iostream>

using namespace std;

const int N = 100;
int A[N][N] = {{0}};
int n;
int t = 0;
int d[N] = {0};
int f[N] = {0};

void dfs(int id) {
    ++t;
    // cerr << "begin: " <<  id << " " << t << endl;
    if (d[id] == 0)
        d[id] = t;

    for (int i = 0; i < n; ++i) {
        if (A[id][i] != 0) {
            dfs(i);
        }
    }

    // cerr << "end: " <<  id << " " << t << endl;
    ++t;
    f[id] = t;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u;
        cin >> u;

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

    dfs(0);

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

    return 0;
}