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) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

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)
	}

	solveDfs(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 <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

int g[101][101],n,d[101],f[101];

int main() {
    cin >> n;
    for(int i = 0;i < n;i++) {
        int u,k,v;
        cin >> u >> k;
        for(int j = 0;j < k;j++) {
            cin >> v;
            g[u][v]++;
        }
    }
    stack<int> dfs;
    int time = 2;
    dfs.push(1);
    d[1] = 1;
    while(!dfs.empty()){
        int u = dfs.top();
        bool fl = false;
        for(int i = 1;i <= n;i++){
            if(g[u][i] && d[i] == 0 && u != i) {
                dfs.push(i);
                d[i] = time++;
                fl = true;
                break;
            }
        }
        if(!fl) {
            dfs.pop();
            f[u] = time++;
        }
    }
    for(int i = 1;i <=n;i++) {
        cout << i << " " << d[i] << " " << f[i] <<endl;
    }
}

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

static const int DFS_VISIT_NO   = 0;
static const int DFS_VISIT_NOW  = 1;
static const int DFS_VISIT_DONE = 2;

static int g_time = 0;
static int g_setime[100][2] = {0};

void DfsVisit(vector<int> graph[], int node, vector<int> &state)
{
    int i;
    int nnum;
    int target;

    ++g_time;
    g_setime[node][0] = g_time;

    state[node] = DFS_VISIT_NOW;
    
    nnum = graph[node].size();

    for (i = 0; i < nnum; i++) {
        target = graph[node][i];
        if (state[target] != DFS_VISIT_DONE) {
            DfsVisit(graph, target, state);
        }
    }

    state[node] = DFS_VISIT_DONE;

    ++g_time;
    g_setime[node][1] = g_time;

    return;
}


void DFS(vector<int> graph[], int num)
{
    int i;
    vector<int> state;

    for (i = 0; i < num; i++) {
        state[i] = DFS_VISIT_NO;
    }

    for (i = 0; i < num; i++) {
        if (state[i] == DFS_VISIT_NO) {
            DfsVisit(graph, i, state);
        }
    }

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

    return;
}

int main(void)
{
    int i, j;
    int target, tnum, node;
    int num;

    scanf("%d", &num);
    vector<int> graph[num];

    for (i = 0; i < num; i++) {
        scanf("%d" "%d", &target, &tnum);
        --target;
        for (j = 0; j < tnum; j++) {
            scanf("%d", &node);
            --node;
            graph[target].push_back(node);
        }
    }

    DFS(graph, num);
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
vector<int> d[120];
bool visit[120];
int cnt = 0;
int fin[120];
int st[120];
void dfs(int p){
	cnt++;
	st[p]=cnt;
	cout <<"p = "<<p<<" cnt = "<<cnt<<endl;
	visit[p]=true;
	for(int i =0;i <d[p].size();i++){
		if(!visit[d[p][i]]){
			dfs(d[p][i]);
		}
	}
	cnt++;
	fin[p]=cnt;

}
int main(){
	int n;
	cin>>n;
	memset(visit, false, sizeof(visit));
	for(int i =0;i < n;i++){
		int u,k;
		cin>>u>>k;
		for(int j =0;j < k;j++){
			int c;
			cin>>c;
			d[u].push_back(c);
		}
	}
	dfs(1);
	/*for(int i =1;i <=n;i++){
		cout <<i<<" "<<st[i]<<" "<<fin[i]<<endl;
	}*/
	return 0;
}

C++: #include<stdio.h>
#define N 100

static const int W=0;
static const int G=1;
static const int B=2;

int M[N][N],color[N],d[N],f[N];
int n,t=0;

void dfs_init(int u){
  int v;
  color[u] = G;
  t++;
  d[u] = t;
  for (v=0;v<n;v++){
    if(M[u][v] == 0)continue;
    if(color[v] == W){
      dfs_init(v);
    }
  }
  color[u] = B;
  t++;
  f[u] = t;
}

void dfs(){
  int i, u;
  for(i=0;i<n;i++)color[i] = W;
 
  for(u=0;u<n;u++){
    if(color[u] == W)dfs_init(u);
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}


int main(){
  int i,j;
  int u,k,v; 
  
  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",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
}

C++: #include <iostream>
#include <array>
#include <algorithm>
#include <stack>

const int nmax = 105;
const int NIL = -1;

int n, t;
// state of vertex
// 0: not visited
// 1: visited
// 2: complete search from the vertex
std::array<int, nmax> color, d, f;

std::array<std::array<int, nmax>, nmax> adj;


void dfs_1v(int v)
{
  d[v] = ++t;
  color[v] = 1;

  for (int j=0; j<n; ++j)
    {
      if (adj[v][j] == 1 && color[j] ==0)
        {
          dfs_1v(j);
        }
    }
  f[v] = ++t;
  color[v] = 2;
}

void dfs()
{
  t = 0;
  for (int i=0; i<n; ++i)
    {
      if (color[i] != 2)
        dfs_1v(i);
    }
}

int main ()
{
  std::cin >> n;

  color.fill(0);
  std::for_each(adj.begin(), adj.end(), [](auto x){x.fill(0);});
  for (int i=0; i<n; ++i)
    {
      int u, k;
      std::cin >> u >> k;
      for (int j=0; j<k; ++j)
        {
          int v;
          std::cin >> v;
          adj[u-1][v-1] = 1;
        }
    }

  dfs();

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

}