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>

#define N_MAX 100

using namespace std;

int t = 1;
int adj_matrix[N_MAX][N_MAX];
int d[N_MAX];
int f[N_MAX];

void dfs(int v, int n)
{
    if (d[v] == 0) {
        d[v] = t;
        t++;
    }
    for (int i = 0; i < n; i++) {
        if (adj_matrix[v][i] != 0) {
            dfs(i, n);
        }
    }
    if (f[v] == 0) {
        f[v] = t;
        t++;
    }
}

int main()
{
    int n, u, k, v;
    cin >> n;
    for (int i = 0; i < n; i++) {
        d[i] = 0;
        f[i] = 0;
    }

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

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

    dfs(0, n);

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

    return 0;
}

C++: #include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
#define lpp(i,n) for(int i = 0; i < n; i++)
int n;
int g[101][103];
void dfs(int v);
using namespace std;
int t = 0;
int main(){
  int u,k,v;
  cin >> n;
  lp(n) {
    cin >> u >> k;
    lpp(j,k) {
      cin >> v;
      g[u][v] = 1;
    }
  }
  int y = 1;
  while(y != 0){
    dfs(y);
    y = 0;
    lp(n) {
      if(g[0][i+1] == 0) {
	y = i+1;
	break;
      }
    }
  }
  lp(n) cout << i+1 << " " << g[i+1][101] << " " << g[i+1][102] << endl;
  return 0;
}
void dfs(int v) {
  g[0][v] = 1;
  g[v][101] = ++t;
  lp(n){
    if(g[v][i+1] == 1 && g[0][i+1] == 0){
      dfs(i+1);
    }
  }
  g[v][102] = ++t;
  /*
  int v;
  int t = 1;
  vector<int> st;
  int *visited = g[0];
  v = 1;
  visited[v] = 1;
  st.push_back(v);
  g[v][101] = t;
  while(!st.empty()) {
    lp(st.size()) cout << st[i]<<" ";cout<<endl;
    v = st.front();
    st.pop_back();
    lp(100) {
      if(g[v][i+1] == 1) {
	if(visited[i+1] == 0) {
	  visited[i+1] = 1;
	  st.push_back(i+1);
	  g[i+1][101] = ++t;
	}
      }
    }
    }*/
}

C++: #include<stdio.h>
struct
{
    int Top=0;
    int s[20000];
    bool Empty()
    {
        return Top==0;
    }
    void push(int x)
    {
        s[++Top]=x;
    }
    void pop()
    {
        Top--;
    }
    int top()
    {
        return s[Top];
    }
}S;
const int N=100;
const int bai=0;
const int hui=1;
const int hei=2;
int n,tu[N][N];
int fx[N],js[N],sum,nt[N],jilu[N];
int next(int u)
{
    for (int v=nt[u];v<n;v++)
    {
        nt[u]=v+1;
        if(tu[u][v]) return v;
    }
    return -1;
}
void DFS_visit(int r)
{

    S.push(r);
    jilu[r]=hui;
    fx[r]=++sum;
    while(!S.Empty())
    {
        int u=S.top();
        int v=next(u);
        if(v!=-1)
        {
            if(jilu[v]==bai)
            {
                jilu[v]=hui;
                fx[v]=++sum;
                S.push(v);
            }
        }
        else
        {
            S.pop();
            jilu[u]=hei;
            js[u]=++sum;    
        }
    }
}
void DFS()
{
    sum=0;
    for (int u=0;u<n;u++)
    {
        if(jilu[u]==bai)
            DFS_visit(u);
    }
    for (int i=0;i<n;i++)
    {
        printf("%d %d %d\n",i+1,fx[i],js[i]);
    }
}
int main()
{
    int u,k,v;
    scanf("%d",&n);
    for (int i=0;i<n;i++)
    {
        scanf("%d%d",&u,&k);
        u--;
        for(int j=0;j<k;j++)
        {
            scanf("%d",&v);
            v--;
            tu[u][v]=1;
        }
    }
    DFS();
    return 0;
}

C++: #include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
/*
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
*/

int table[101][101], time_table[101][2];
int common_time = 1, n;

void dfs(int node){
    if(time_table[node][0] == 0) time_table[node][0] = common_time++;
    else return;
    for(int i = 1; i <= n; i++){
        if(table[node][i] == 1) dfs(i);
    }
    time_table[node][1] = common_time++;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    int id, k, v;
    rep(i,n+1){
        rep(j,n+1) table[i][j] = 0;
        time_table[i][0] = 0;
        time_table[i][1] = 0;
    }
    rep(i,n){
        cin >> id >> k;
        rep(j,k){
            cin >> v;
            table[id][v] = 1;
        }
    }
    for(int i = 1; i <= n; i++){
        dfs(i);
    }
    for(int i = 1; i <= n; i++){
        cout << i << " " << time_table[i][0] << " " << time_table[i][1] << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int n,g[100][100],c[100],f[100],e[100],t=1;
void dfs(int now){
  c[now]=1;
  f[now]=t;
  t++;
  for(int i=0;i<n;i++) if(g[now][i]&&c[i]!=1){
      dfs(i);
      t++;
    }
  e[now]=t;
}
int main(){
 
  int a,b,tmp;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    for(int j=0;j<b;j++){
      cin>>tmp;
      g[a-1][tmp-1]=1;
    }
  }
  for(int i=0;i<n;i++) if(c[i]!=1){
      dfs(i);
      t++;
    }
 
  for(int i=0;i<n;i++) cout<<i+1<<" "<<f[i]<<" "<<e[i]<<endl;
 
  return 0;
 
}