Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

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

using namespace std;

/*****************************************/
/*         Function prototype            */
/*****************************************/

vector<vector<int> > list_to_mat(vector<vector<int> >& adj);
void dump_mat( vector<vector<int> >& mat);
void dfs(vector<vector<int> >& adj_list, int now, vector<int>& d, vector<int>& f, int *t);

/*****************************************/
/*            Main Function              */
/*****************************************/


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

  vector<vector<int> > list(n+1);
  for(int i=0; i<n; i++){
    int u,k; cin >> u >> k;
    vector<int> tmp(k);
    for(int j=0; j<k; j++) cin >> tmp[j];
    sort(tmp.begin(),tmp.end());
    list[u] = tmp;
  }
  int t=1;
  vector<int> d(n+1,-1);
  vector<int> f(n+1,-1);

  dfs(list,1,d,f,&t);

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



/*****************************************/
/*            Implimentation             */
/*****************************************/


void dfs(vector<vector<int> >& adj_list, int now, vector<int>& d, vector<int>& f, int* t){
  d[now] = *t;
  (*t)++;
  
  for(auto v : adj_list[now]){
    if(d[v] != -1) continue;
    dfs(adj_list, v, d, f, t);
  }
  f[now] = *t;
  (*t)++;
  return ;
}


vector<vector<int> > list_to_mat(vector<vector<int> >& adj){
  const int mat_size = (int)adj.size();
  vector<vector<int> > ans(mat_size,vector<int>(mat_size,0));
  for(int i=0; i<mat_size; i++){
    for(int j=0; j<adj[i].size(); j++){
      ans[i][adj[i][j]-1] = 1;
    }
  }
  return ans;
}


void dump_mat( vector<vector<int> >& mat){
  
  const int mat_size = (int)mat.size();
  for(int i=0; i<mat_size; i++){
    for(int j=0; j<mat[i].size(); j++){
      cout << mat[i][j];
      if(j!=mat[i].size()-1)
	cout << " ";
      else
	cout << "\n";
    }
  }
}

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>
using namespace std;
int arisutoteresu[200][200] = {0};
int imap[200][200] = {0};
int n,u,k[200];
int GetIt[200]={0};
int FinIt[200]={0};
bool used[200] = {false};
int fincou=1;
void dfs(int where,int find){
  fincou++;
 
  GetIt[where]=find;
  if(k[where] != 0){
    for(int i=0;i<k[where];i++){
      if(!used[where]){
	dfs(imap[where][i],find+1);
	fincou++;
	used[where] = true;
      }
    }
  }
    FinIt[where] = fincou;
    
}

int main(){
 
  int ad;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> u;
    cin >> k[u];
    for(int j=0;j<k[u];j++){
      cin >> ad;
      arisutoteresu[u][ad] = 1;
      imap[u][j] = ad; 
    }
  }


  for(int j=0;j<n;j++)used[j] = false;
  dfs(1,1);

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

  return 0;
}

C++: #include <stdio.h>
int size[101],g[101][101],x[101], y[101], k, d;
void dfs(int z){
  int i;
  x[z] = d++;
  for(i=1;i<=size[z];i++) if(!x[g[z][i]]) dfs(g[z][i]);
  y[z] = d++;
}
 
main(){
  int i, j, a;
  d=1;
  scanf("%d", &k);
  for(i=1;i<=k;i++){
    x[i] = y[i] = 0;
    scanf("%d", &a);
    scanf("%d", &size[a]);
    for(j=1;j<=size[a];j++) scanf("%d", &g[a][j]);
  }
  for(i=1;i<=k;i++){
    if(!x[i]) dfs(i);
  }
  for(i=1;i<=k;i++){
    printf("%d %d %d\n", i, x[i], y[i]);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

const int MAX_N = 100;
const int INF = 1e9;

int n;
int d[MAX_N], f[MAX_N];
vector<int> g[MAX_N];

int t = 1;

void dfs(int v) {
    if (d[v] == INF) d[v] = t++;
    for (auto u : g[v]) {
        if (d[u] == INF) dfs(u);
    }
    if (f[v] == INF) f[v] = t++;
}

int main() {
    fill(d, d+MAX_N, INF);
    fill(f, f+MAX_N, INF);
    cin >> n;
    for (int i = 0, u, k; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0, v; j < k; j++) {
            cin >> v;
            v--;
            g[u].push_back(v);
        }
    }
    for (int i = 0; i < n; i++) dfs(i);
    for (int i = 0; i < n; i++) {
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}

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

void dfs_init();
void dfs(int u);

int n,*d,*f,time;
string *color; bool **M;

int main(){
	cin>>n;
	color = new string[n];
	M = new bool*[n]; for(int i=0;i<n;i++) M[i] = new bool[n];
	d = new int[n]; f = new int[n];

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

	int deg,vertex,temp;
	for(int i=0;i<n;i++){
		cin>>vertex>>deg;
		for(int j=0;j<deg;j++){
			cin>>temp;
			M[vertex-1][temp-1] = true;
		}
	}

	dfs_init();

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

	delete [] color;
	for(int i=0;i<n;i++) delete [] M[i]; delete [] M;
	delete [] d; delete [] f;
}

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

void dfs(int u){
	color[u] = "GRAY";
	d[u] = ++time;
	for(int v=0;v<n;v++){
		if(M[u][v] && color[v]=="WHITE")
			dfs(v);
	}
	color[u] = "BLACK";
	f[u] = ++time;
}