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<stdio.h>

void depthfs(void);

void visit(int);

#define MAX 109

#define WHITE 0
#define GRAY 1
#define BLACK 2

int graph[MAX][MAX];

int n;
int time;
int d[MAX],f[MAX];
int color[MAX];

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

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){    
      graph[i][j] = 0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&num);
    for(j=0;j<num;j++){
      scanf("%d",&v);
      graph[u][v] = 1;
    }
  }

  depthfs();

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

  
  return 0;

}

void depthfs(void){
  int i;
  //for each vertex u in V
  for(i=1;i<=n;i++){
  color[i] = WHITE;
  d[i] = 0;
  f[i] = 0;
  }

  time= 0;

  //for each vertex u in V
  for(i=1;i<=n;i++){
  if(color[i] == WHITE) visit(i);
  }

}

void visit(int x){
  int i;

  color[x] = GRAY;//white vertex u has just been discovered

  d[x] = ++time;

  //for each v in adj[u] //explore edge(u,v)

  for(i=1;i<=n;i++){
    if(graph[x][i] == 1){
      if(color[i] == WHITE) visit(i);
    }
  }

  color[x] = BLACK; //blacken u; it is finished

  f[x] = ++time;
  
}

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

int m[101][101];
int visit[101];
int d[101];
int f[101];
int n, t;

void dfs(int u){
  visit[u] = 1;
  d[u] = t;
  t++;
  
  for(int i = 0; i < n; ++i){
    if(m[u][i] == 1 && visit[i] == 0){
      dfs(i);
    }
  }

  f[u] = t;
  t++;
}

main()
{
  int u, k, v;
  
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> u >> k;
    --u;
    for(int j = 0; j < k; ++j){
      cin >> v;
      v--;
      m[u][v] = 1;
    }
  }

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

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

  return (0);
}

C++: #include <iostream>

using namespace std;

int V[100][100];
int n;

int d[100];
int f[100];

int t = 1;
void dfs(int src){
  t++;
  for(int i=1;i<=n;i++){
    if(V[src][i] != 0 && !d[i]){
      d[i] = t;
      dfs(i);
      t++;
    }
  }
  f[src] = t;
}
int main(){
  int  src, dst, num;
  cin >> n;
  for(int i=1;i<=n;i++){
    d[i] = 0; f[i] = 0;
  }
  for(int i=1;i<=n;i++){
    cin >> src >> num;
    for(int j=0;j<num;j++){
      cin >> dst;
      V[src][dst] = 1;
    }
  }
  d[1] = 1;
  dfs(1);
  for(int i=1;i<=n;i++){
    cout << i <<" "<< d[i] <<" "<< f[i] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int n;
int common_time=1;
int g[110][110];
int d[10000];
int f[10000];

int dfs(int node){
  if(d[node]==0){
    d[node]=common_time++;
    //cout<<node<<" "<<d[node]<<"#"<<endl;
  }
  else{
    return 0;
  }
  for(int i=0;i<=n;i++){
    if(g[node][i] == 1){
      //cout<<node<<"$"<<i<<endl;
			dfs(i);
    }
  }
	f[node] = common_time++;
  //cout<<node<<" "<<f[node]<<"&"<<endl;
}

int main(){

  cin>>n;

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

  for(int i=0;i<10000;i++){
    d[i]=0;
    f[i]=0;
  }
  int u;
  int k;
  int v;
  for(int i=0;i<n;i++){
    cin >>u;
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      g[u-1][v]=1;
      //g[v][u-1]=1;
    }
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      //cout<<g[i][j];
    }
    //cout<<endl;
  }
  
 for(int i=0;i<n;i++){
  dfs(i);
 }
  
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int G[101][101];
int d[101];
int f[101];
bool flag[101];
int n,v,k,p;
int t;

void check(int i){
	if(flag[i])return;
	flag[i]=true;
	t++;
	d[i]=t;
	for(int j=1;j<=n;j++){
		if(G[i][j]==1)check(j);
	}
	t++;
	f[i]=t;
	return;
}


int main(){
	cin >>n;
	for(int i=0;i<n;i++){
		cin >> v>>k;
		for(int j=0;j<k;j++){
			cin >> p;
			G[v][p]=1;
		}
	}
	t=0;
	check(1);
	for(int i=1;i<=n;i++){
		cout << i<< " "<<d[i]<< " "<<f[i] <<endl;
	}
}

C++: #include<iostream>
using namespace std;
struct T{int first,last;};
struct T ttt[200];
int n,ch[200],u,V[200][200],ti=1,a;
bool Discovery[200];
void search(int p){
    ttt[p].first=ti;ti++;
    int x;
    Discovery[p]=true;
    for(int i=1;i<=ch[p];i++){
        x=V[p][i];
        if(!Discovery[x]) search(x);
    }
    ttt[p].last=ti; ti++;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a>>ch[i];
        Discovery[i]=false;
        for(int j=1;j<=ch[i];j++){
            cin>>V[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        if(!Discovery[i]) search(i);
    }
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<ttt[i].first<<" "<<ttt[i].last<<endl;
    }
    return 0;
}