Go: package main

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

func main() {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	nextInt := func() int { scn.Scan(); r, _ := strconv.Atoi(scn.Text()); return r }
	w := bufio.NewWriter(os.Stdout)

	n := nextInt()
	vecs := make([][]int, n)
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			vecs[u-1] = append(vecs[u-1], nextInt()-1)
		}
	}

	ds := make([]int, n)
	fs := make([]int, n)
	founds := make([]bool, n)
	t := 0
	for i := range founds {
		if !founds[i] {
			t = dfs(vecs, ds, fs, founds, i, t)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(w, i+1, ds[i], fs[i])
	}

	w.Flush()
}

func dfs(vecs [][]int, ds, fs []int, founds []bool, i, t int) (time int) {
	t++
	ds[i] = t
	founds[i] = true
	for _, v := range vecs[i] {
		if !founds[v] {
			t = dfs(vecs, ds, fs, founds, v, t)
		}
	}
	t++
	fs[i] = t

	return t
}

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

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]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++) color[u] = WHITE;
  tt=0;

  for(u=0;u<n;u++){
    if(color[u] == WHITE) 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",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();
  
  return 0;
}

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

using namespace std;

const int WHITE = 0, GREY = 1, BLACK = 2;

struct DFS {
    int n;
    vector<vector<int>> g;
    vector<int> color;
    int ct = 1; //current time
    vector<int> dt; //discover time
    vector<int> ft; //finish time
    
    DFS(int n) : n(n) {
        g.assign(n, vector<int>());
        color.assign(n, WHITE);
        dt.assign(n, -1);
        ft.assign(n, -1);
    }
    
    void addEdge(int u, int v) {
        g[u].push_back(v);
    }
    
    void dfs() {
        for (int i = 0; i < n; i++) {
            if (color[i] == WHITE) {
                dfsVisit(i);
            }
        }
    }
    
    void dfsVisit(int u) {
        //cout << "visited: " << u << endl;
        color[u] = GREY;
        dt[u] = ct++; //first assign ct to dt[u], then ++
        for (int v : g[u]) {
            if (color[v] == WHITE) {
                dfsVisit(v);
            }
        }
        color[u] = BLACK;
        ft[u] = ct++;
    }
    
    void printGraph() {
        for (int i = 0; i < n; i++) {
            cout << i << ": ";
            for (int j : g[i]) {
                cout << j << " ";
            }
            cout << endl;
        }
    }
    
    void printResults() {
        for (int i = 0; i < n; i++) {
            cout << i + 1 << " " << dt[i] << " " << ft[i] << endl;
        }
    }
};

int main() {
    int n;
    cin >> n;
    DFS dfs(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            dfs.addEdge(u - 1, v - 1);
        }
    }
    
    //dfs.printGraph();
    dfs.dfs();
    dfs.printResults();
    
    return 0;
}

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

using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

//次の辺があれば返す
int next(int u){
    for(int v = nt[u]; v < n; ++v){
        nt[u] = v + 1;
        if( M[u][v] )
            return v;
    }
    return -1;
}

void dfs_visit(int r){
    for(int i = 0; i<n; i++)
        nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while( !S.empty() ){
        int u = S.top();
        int v = next(u);
        if( v != -1 ){
            if( color[v] == WHITE ){
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs(){
    for (int i = 0; i < n; i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

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

int main()
{
    int u, k, v;

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

    dfs();

    return 0;
}

C++: #include <iostream>

using namespace std;
int n,u,k,v,**M,flag[100],s_time[100],f_time[100];
void creat()
{
    cin>>n;
  M=new int*[n];
  for(int i=0;i<n;i++)
    {
      M[i]=new int[n];
      flag[i]=0;
      for(int j=0;j<n;j++)
	M[i][j]=0;
    }
  int count=0;
  while(count<n)
    {
      count++;
      cin>>u>>k;
      for(int i=0;i<k;i++)
	{
	  cin>>v;
	  M[u-1][v-1]=1;
	}
    }
    /*for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)
      cout<<M[i][j]<<' ';
    cout<<endl;
  }*/
}
int Time;
void dfs(int cur) {
    Time += 1;
    s_time[cur]=Time;
    //cout << "visiting " << cur+1 << ' ' << time << endl;
    flag[cur]=1;
    for (int dst=0;dst<n;dst++) {
            if (M[cur][dst]&&!flag[dst]) {
                dfs(dst);
            }
    }
    Time += 1;
    f_time[cur]=time;
}
int main()
{
    Time=0;
    creat();
    for(int i=0;i<n;i++)
    {
        if(!flag[i])
            dfs(i);
    }
    for(int i=0;i<n;i++)
    {
        cout<<i+1<<' '<<s_time[i]<<' '<<f_time[i]<<endl;
    }
    delete M;
    return 0;
}