Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

int n, u, k, v;
int d[101], f[101];
pair<int, vector<int> > G[101];

int ti = 1;

void dfs(int id) {
	if (d[id]) return ;
	d[id] = ti ++;

	vector<int>& adj = G[id].second;
	for (int i=0; i<(int)adj.size(); ++i) {
		dfs(adj[i]);
	}
	f[id] = ti ++;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> u >> k;
		G[u].first = u;
		while (k --) {
			cin >> v;
			G[u].second.push_back(v);
		}
	}
	for (int i=1; i<=n; ++i) {
		dfs(i);
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

int stack[100], sp;
int start[100], end[100];
int ti;

void dfs(int , int **);
void visit(int , int **, int *);
int pop();
void push(int);

int main(){

  int i, j;
  int n, u , k;
  int **a;

  scanf("%d", &n);

  a = (int **)malloc(sizeof(int *) * n);

  for(i = 0; i < n; i++){
    scanf("%d%d", &u, &k);

    a[i] = (int *)malloc(sizeof(int) * k + 1);
    a[i][k] = -1;

    for(j = 0; j < k; j++){
      scanf("%d", &a[i][j]);
    }

  }

  dfs(n, a);

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


  return 0;
}

void dfs(int n, int **a){

  int i;
  int color[100];

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

  for(i = 0; i < n; i++){
    if(color[i] == 0) visit(i, a, color);
  }

}

void visit(int u, int **a, int *c){

  int i;
  int v;

  printf("%d\n", u);

  c[u] = 1;
  start[u] = ++ti;

  for(i = 0; a[u][i] != -1; i++){
    v = a[u][i] - 1;
    if(c[v] == 0) visit(v, a, c); 

  }  

  c[u] = 2;
  end[u] = ++ti;

}

int pop(){

  sp--;

  return stack[sp];
}


void push(int d){

  stack[sp] = d;

  sp++;

}

C++: #include<iostream>
#include<cstdio>
#define N 100
#define  GRAY 1
#define BLACK 2
using namespace std;
int n,M[N][N];
int color[N],d[N],f[N],tt;
void dfs_visit(int u)
{
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v = 0;v<n;v++)
  {  
    if(M[u][v] == 0)
     continue;
  if(color[v] == 0)
    {
      dfs_visit(v);
    }
}
  color[u] = BLACK;
  f[u] == ++tt;
}
void dfs()
{
  int u;
  for(u = 0;u<n;u++)
     color[u] = 0;
  tt = 0;
  for(u = 0;u<n;u++)
  {
    if(color[u] == 0) dfs_visit(u);
  }
  for(u = 0;u<n;u++)
  {
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
int main ()
{
  int u,v,k,i,j;
  scanf("%d",&n);
  for( i = 0;i<n;i++)
  {  for( j = 0;j<n;j++)
        M[i][j] = 0; }
  for( i =0;i<n;i++)
   {
     scanf("%d %d",&n,&k);
     u--;
     for( j = 0;j<k;j++)
       {
         scanf("%d",&v);
         v--;
         M[u][v] = 1;
       }
   }
   dfs();
  return  0 ;
}

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

int n,t;
int d[100],f[100];
bool graph[100][100], visited[100];

void dfs(int v){
    visited[v]=true;
    t++;
    d[v]=t;

    for(int v2=0; v2<n; v2++){
        if(graph[v][v2] && visited[v2]==false) dfs(v2);
    }

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

int main(void){
    cin >> n;
    t=0;

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            graph[i][j]=false;
        }
    }
    for(int i=0; i<n; i++){
        int v,k; cin >> v >> k;
        for(int j=0; j<k; j++){
            int w; cin >> w;
            graph[v-1][w-1]=true;
        }
    }

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

C++: #include<bits/stdc++.h>
using namespace std;
int a[101][101],num[101],tt[101][2];
bool vis[101];
int n,u,k,x,t=1;
void dfs(int k){
     tt[k][0]=t; t++;
     vis[k]=true;
	 for (int i=1; i<=num[k]; i++){
	     if (!vis[a[k][i]]){
	     	dfs(a[k][i]);
		 }
     }
	 tt[k][1]=t; t++;
}
int main(){
	memset(a,0,sizeof(a));
	memset(vis,false,sizeof(vis));
	cin>>n;
	for (int i=0; i<n; i++){
		cin>>u>>k;
		num[u]=k;
		int j=0;
		while (k--){
			  cin>>x;
			  a[u][++j]=x;
		}
	}
	for (int i=1; i<=n; i++)
	    if (!vis[i])
		   dfs(i); 
	for (int i=1; i<=n; i++){
		cout<<i;
		for (int j=0; j<2; j++)
		    cout<<' '<<tt[i][j];
		cout<<'\n';
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

	int time = 0;
	int d[101];
	int f[101];
	int num;
	int graph[101][101] = {0};

void dfs(int x){
	time++;
	d[x] = time;

	for(int i=1;i<=num;i++){
		if(graph[x][i] == 1 && d[i]==0){
			printf("%d -> %d\n",x,i);
			dfs(i);
		}
	}
	f[x] = ++time;
}

int main(){
	int hon;
	int eda;
	int ver;

	cin>>num;
	for(int i=0;i<num;i++){
		cin>>eda;
		cin>>hon;
		for(int j=0;j<hon;j++){
			cin>>ver;
			graph[eda][ver]++;
		}
	}

	dfs(1);

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

	return 0;
}

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

using namespace std;

vector<int> d(101, -1), f(101, -1);
vector<vector<int> > c;

int n, u, k, v;
int dfs(int node, int time) {
    d[node] = time;
    for(int i=0; i<n; ++i) {
        if(c[node][i]==1&&d[i]==-1) time = dfs(i, time+1);
    }
    time++;
    f[node] = time;
    return time;
}

int main() {
    cin >> n;
    for(int i=0; i<n; ++i) {
        cin >> u >> k;
        vector<int> tmp(100, 0);
        for(int j=0; j<k; ++j) {
            cin >> v;
            tmp[v-1] = 1;
        }
        c.push_back(tmp);
    }

    bool isFinished = false;
    int node = 0;
    int time = 0;
    while(isFinished==false) {
        time++;
        time = dfs(node, time);
        isFinished = true;
        for(node=0; node<n; node++) {
            if(d[node]==-1) {
                isFinished=false;
                break;
            }
        }
    }
    for(int i=0; i<n; ++i) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}