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<stdio.h>
 
#define MAX 101
#define WHITE -1
#define GRAY 0
#define BLACK 1
 
int n,t;
int color[MAX],d[MAX],f[MAX],Adj[MAX][MAX];
 
dfs(){
  int i;
 
  for(i=0;i<n;i++) color[i]=WHITE;
  t=0;
  for(i=0;i<n;i++){
    if(color[i]==WHITE) visit(i);
  }
}
 
visit(int r){
  int i;
 
  color[r]=GRAY;
  d[r]=++t;
 
  for(i=0;i<n;i++){
    if(Adj[r][i]==1 && color[i]==WHITE) visit(i);
  }
 
  color[r]=BLACK;
  f[r]=++t;
}
 
int main(){
  int i,u,k,j,v;
 
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){ 
      Adj[i][j]=0;
    }
  }
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      Adj[u-1][v-1]=1;
    }
  }
 
  dfs();
 
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
 
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define EXIST 1
#define TODO 1
#define DONE 0
int graph[200][200];
int used[200];
int disc[200];
int fin[200];
int n;
int elapsed;

void dfs(int pos) {
  disc[pos] = ++elapsed;
  used[pos] = DONE;
  for (int i = 0; i < n; i++) {
    if (graph[pos][i] == EXIST && used[i] == TODO) {
      dfs(i);
    }
  }
  fin[pos] = ++elapsed;
}

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;
      graph[u-1][v-1] = EXIST;
    }
    used[i] = TODO;
  }
  for (int i = 0; i < n; i++) {
    if (used[i] == TODO) {
      dfs(i);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i+1 << " " << disc[i] << " " << fin[i] << endl; 
  }
}

C++: #include<iostream>
#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",u+1,d[u],f[u]);
    }
}

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

    dfs();
    return 0;
}

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

using namespace std;

int** gmtrx;
int* d, *f;
int t, n;

class Stack{
public:
	Stack(int num):head(0){
		s = new int [num];
		for(int i=0; i<num; ++i){
			s[i] = 0;
		}
	}
	~Stack(){ delete[] s; }
	void push_back(int vtx){
		s[head++] = vtx;
	}
	int pop_back(){
		--head;
		int tmp = s[head];
		s[head] = 0;
		return tmp;
	}
	int back(){
		if(head<=0) return -1;
		return s[head-1];
	}
private:
	int head;
	int* s;
};


int main()
{
	scanf("%d",&n);

	gmtrx = new int*[n];
	d = new int [n]; //discovery
	f = new int [n]; //finish
	Stack st(n);

	for(int i=0; i<n; ++i){
		gmtrx[i] = new int[n];
		for(int j=0; j<n; ++j){
			gmtrx[i][j] = 0;
		}
		d[i] = 0;
		f[i] = 0;
	}

	for(int i=0; i<n; ++i){
		int v, num, a;
		scanf("%d %d",&v,&num);
		--v;
		for(int j=0; j<num; ++j){
			scanf("%d",&a);
			--a;
			gmtrx[v][a] = 1;
		}
	}

	for(int i=0; i<n; ++i){
		int vtmp=i;
		if( d[vtmp]!= 0) continue;
		st.push_back(vtmp);
		vtmp=0;
		while(st.back()!=-1){
			if(d[st.back()]==0){
				++t;
				d[st.back()] = t;
			}
			else if(f[st.back()]!=0){
				vtmp = st.pop_back();
				++vtmp;
				continue;
			}
			for(int j=vtmp; j<=n; ++j){
				if(j==n){
					++t;
					f[st.back()] = t;
					vtmp = st.pop_back();
					++vtmp;
					break;
				}
				if(gmtrx[st.back()][j]){
					if(d[j]==0) st.push_back(j);
					else continue;
					break;
				}
			}
		}
	}

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

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

	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int Adj[n][n] = {};
    int time[n][2] = {};
    for (int i = 0; i < n; i++)
    {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            Adj[u - 1][v - 1] = 1;
        }
    }

    stack<int> s;
    int current_time = 1;
    for (int i = 0; i < n; i++)
    {
        if (time[i][0] == 0)
        {
            int src = i;
            s.push(src);
            while (!s.empty())
            {
                int cur = s.top();
                s.pop();
                //cout << cur << " " << current_time << endl;
                if (time[cur][0] == 0)
                {
                    time[cur][0] = current_time;
                    s.push(cur);
                    for (int dst = n - 1; dst >= 0; dst--)
                    {
                        //cout << cur << " " << dst << " " << Adj[cur][dst] << endl;
                        if (Adj[cur][dst] && time[dst][0] == 0)
                        {
                            s.push(dst);
                        }
                    }
                    current_time++;
                }
                else if (time[cur][0] != 0 && time[cur][1] == 0)
                {
                    time[cur][1] = current_time;
                    current_time++;
                }
            }
        }
    }

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

    return 0;
}