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 <map>
using namespace std;

map<int, vector<int>> A;
int color[101];
int start[101];
int endTime[101];
int elapsed = 0;

void dfs(int u) {
    elapsed++;
    color[u] = 1;
    start[u] = elapsed;
    for (vector<int>::iterator it = A[u].begin(); it != A[u].end(); it++) {
        if (color[*it] == 0) {
            dfs(*it);
        }
    }
    endTime[u] = ++elapsed;
}

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

    int u, k;
    for (int i = 1; i <= n; i++) {
        color[i] = 0;
        cin >> u >> k;
        int ad;
        for (int j = 0; j < k; j++) {
            cin >> ad;
            A[u].push_back(ad);
        }
    }

    for (int i = 1; i <= n; i++) {
        if (color[i] == 0) dfs(i);
    }

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

C++: #include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

struct Timestamp{
	int discovered;
	int finished;
};

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

	set<int> A[n+1];
	bool reached[n+1]{};
	int v1, v2, deg;
	r(i, n){
		cin >> v1 >> deg;

		r(j, deg){
			cin >> v2;
			A[v1].insert(v2);
			//A[v2].insert(v1);
		}
	}

	Timestamp ts[n+1];
	for(int i = 1; i <= n; i++){
		ts[i].discovered = 0;
		ts[i].finished = 0;
	}
	ts[1].discovered = 1;


	int time = 0;
	stack<int> s;

	while(true){
		for (int i = 1; i <= n; i++) {
			if (reached[i])
				continue;
			reached[i] = true;
			s.push(i);
			time++;
			ts[i].discovered = time;
			goto DFS;
		}
		break;

		DFS:;
		while (!s.empty()) {
			v1 = s.top();

			bool hasNext = false;
			for (int v2 : A[v1]) {
				if (!reached[v2]) {
					reached[v2] = true;
					s.push(v2);
					hasNext = true;
					break;
				}
			}

			if (!ts[v1].discovered) {
				time++;
				ts[v1].discovered = time;
			}

			if (!hasNext) {
				time++;
				ts[v1].finished = time;
				s.pop();
			}
		}
	}

	for(int i = 1; i <= n; i++){
		printf("%d %d %d\n", i, ts[i].discovered, ts[i].finished);
	}

	return 0;
}

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

std::vector<pair<int, int> > stamp(101);
std::vector<std::vector<int> > v(101);
bool isCheckd[101];
int cnt = 0;

void dfs(int k){
	cnt++;
	isCheckd[k] = true;
	stamp[k].first = cnt;
	for(int i=0;i<v[k].size();i++){
		int next = v[k][i];
		if(!isCheckd[next]){
			dfs(next);
		}
	}
	cnt++;
	stamp[k].second = cnt;
}

int main(){
	int n;

	fill(isCheckd,isCheckd+101,false);
	isCheckd[0] = true;
	cin >> n;

	for(int i=0;i<n;i++){
		int u,k;
		cin >> u >> k;
		for(int j=0;j<k;j++){
			int in;
			cin >> in;
			v[u].push_back(in);
		}
	}

	for(int i=0;i<n;i++){
		if(!isCheckd[i])
			dfs(i);
	}


	for(int i=0;i<n;i++){
		cout << i+1 <<" "<< stamp[i+1].first <<" " <<stamp[i+1].second<< endl;
	}

	return 0;
}

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++: //
//  main.cpp
//  depth_first_search
//
//  Created by ???????????? on 2017/10/22.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>

#define n_max 100

using namespace std;

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

void encode_graph(int n){
    int i, j, id, num, node;
    
    //initialize with 0
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            M[i][j] = 0;
        }
    }
    
    for (i = 0; i < n; i++){
        scanf("%d", &id);
        scanf("%d", &num);
        for(j = 0; j < num; j++){
            scanf("%d", &node);
            M[id-1][node-1] = 1;
        }
    }
}

void dfs(int u){
    color[u] = 1;
    d[u] = ++t;
    for (int v = 0; v < n; v++){
        if((M[u][v]) && (color[v] == 0)){
            dfs(v);
        }
    }
    color[u] = 2;
    f[u] = ++t;
}

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


int main(int argc, const char * argv[]) {
    scanf("%d", &n);
    
    encode_graph(n);
    
    dfs_init(n);
    
    for(int i = 0; i < n; i++){
        cout<<i+1<<" "<<d[i]<<" "<< f[i]<<endl;
    }
    
//    std::cout << "Hello, World!\n";
    return 0;
}

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

int n;
int k;
int color[100];
int a[100],b[100],c;
int adj[110][110];

void deepread(int k){
  int h;
  color[k]=1;
  a[k]=++c;
  for(h=0;h<n;h++){
    if(adj[k][h]==0){
      continue;
    }
    if(color[h]==0){
      deepread(h);
    }
  }
  color[k]=3;
  b[k]=++c;
}

void deep(){
  for(int i=0;i<n;i++){
    color[i]=0;
  }
  c=0;
  for(int k=0;k<n;k++){
    if(color[k]==0)deepread(k);
  }
  for(int k=0;k<n;k++){
    cout<<k+1<<" "<<a[k]<<" "<<b[k]<<endl;
  }
}


int main(){
  int num;
  cin>>n;
  int rin;
  int i=0,j=0;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      adj[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    cin>>num>>k;
    num--;
    for(j=0;j<k;j++){
      cin>>rin;
      rin--;
      adj[num][rin]=1;
    }
  }
  /*for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j)cout<<" ";
      cout<<adj[i][j];
    }
    cout<<endl;
    }*/

  deep();
  return 0;
}