Go: package main

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

/***************************************************************
stackによる深さ優先探索を実装する。
***************************************************************/

const (
	N     = 100
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

var (
	n            int
	Adj          [N][N]int
	statusColor  [N]int
	discoverTime [N]int
	finishTime   [N]int
	clock        int
	nt           [N]int
)

/***************************************************************
Stackの定義:
- field
	container: ノードの格納されたスライス
	sp: スタックポインタ
- method
	size(): スタックに積まれているノードの個数を返す
	top(): スタックの一番上に積まれているノードを返す
	isEmpty(): スタックが空かどうかを返す
	pop(): スタックの要素をポップし削除する
	push(): スタックに要素を積む
***************************************************************/

type Stack struct {
	container []int
	sp        int
}

func (s *Stack) size() int {
	return len(s.container)
}

func (s *Stack) top() int {
	return s.container[s.sp]
}

func (s *Stack) isEmpty() bool {
	return s.sp == 0
}

func (s *Stack) pop() int {
	_pop := func() {
		s.container = s.container[:len(s.container)-1]
	}
	defer _pop()
	if s.isEmpty() {
		panic("There is no elements in stack!")
	}
	s.sp--
	return s.container[s.sp]
}

func (s *Stack) push(n int) {
	s.sp++
	s.container[s.sp] = n
}

func next(u int) int {
	for v := nt[u]; v < n; v++ {
		nt[u] = v + 1
		if Adj[u][v] == 1 {
			return v
		}
	}
	return -1
}

func _DFS(target int) {
	for i := 0; i < n; i++ {
		nt[i] = 0
	}
	stack := new(Stack)
	stack.container = make([]int, N+1)
	stack.push(target)
	statusColor[target] = GRAY
	clock++
	discoverTime[target] = clock
	for !stack.isEmpty() {
		u := stack.top()
		v := next(u)
		if v != -1 {
			if statusColor[v] == WHITE {
				statusColor[v] = GRAY
				clock++
				discoverTime[v] = clock
				stack.push(v)
			}
		} else {
			stack.pop()
			statusColor[u] = BLACK
			clock++
			finishTime[u] = clock
		}
	}
}

func DFS() {
	for i := 0; i < n; i++ {
		statusColor[i] = WHITE
		nt[i] = 0
	}
	clock = 0
	for i := 0; i < n; i++ {
		if statusColor[i] == WHITE {
			_DFS(i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, discoverTime[i], finishTime[i])
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			Adj[i][j] = 0
		}
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		u, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		u--
		for j := 0; j < k; j++ {
			scanner.Scan()
			v, _ := strconv.Atoi(scanner.Text())
			v--
			Adj[u][v] = 1
		}
	}

	DFS()
}

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

using namespace std;
int timetime = 0;

void dfs(int cur, vector<vector <int> > &list, vector<int> &d, vector<int> &f) {
		d[cur] =timetime;
		timetime +=1;
    for(int i = 0; i < list.size();i++){
      vector<int>::iterator n1end = list[cur].end();
	  vector<int>::iterator n1sres = find(list[cur].begin(),list[cur].end(),i);
      if(d[i] == -1 &&  n1end != n1sres  ){
        dfs(i,list,d,f);
      }
    }
    f[cur] = timetime;
    timetime +=1;
}

int main() {
  int np;
  int k,t,x;
  cin >> np ;
 
  vector <vector <int> > list(np);
  for(int i = 0;i<np;i++) {
    cin >> k;
    cin >> t;
    for(int j = 0; j < t ;j++) {
      cin >>x;
      list[k-1].push_back(x-1);
    }
  }
  for(int i = 0 ; i< np;i++){
	sort(list[i].begin(),list[i].end());
  }
  vector <int> d(np,-1);
  vector <int> f(np,0);
  dfs(0,list,d,f);
  	  int flag =0;
  do {
	  flag = 0;
	  for(int i = 0; i< np ;i++) {
		if(d[i] == -1){
				  dfs(i,list,d,f);
				  flag = 1;
				  break;
		}
	  }

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


  return 0;
}

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

int n;
int time_count = 0;
std::vector<std::pair<int, int>> times;
std::vector<std::vector<int>> vec;

void dfs(int id) {
    if (times[id-1].first == -1) {
        times[id-1].first = ++time_count; 
        for (int i = 1; i <= n; i++) {
            if (vec[id][i] == 1 && times[i-1].first == -1) {
                dfs(i);
            }
        }
        times[id-1].second = ++time_count;
    }
}

int main() {
    std::cin >> n;
    vec.assign(n+1, std::vector<int>(n+1, 0));
    for (int i = 0; i < n; i++) {
        times.push_back(std::make_pair(-1, -1));
    }
    for (int i = 0; i < n; i++) {
        int id, num, d;
        std::cin >> id >> num;
        for (int p = 0; p < num; p++) {
            std::cin >> d;
            vec[id][d] = 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        dfs(i);
    }
    
    for (int i = 0; i < n; i++) {
        std::cout << i+1 << " " << times[i].first << " " << times[i].second << std::endl;
    }
}

C++: #include<iostream>
#include<vector>
#define NIL -1
using namespace std;

void DFS(int id, const vector<vector<int> >& a,
          vector<int>& find, vector<int>& finish){
    static int t = 1;
    if (find[id] != NIL) return;
    find[id] = t++;
    for (int i = 0; i < a[id].size(); i++) {
        DFS(a[id][i], a, find, finish);
    }
    finish[id] = t++;
}

int main(){
    int n;
    cin >> n;
    vector<vector<int> > a(n + 1);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            a[u].push_back(v);
        }
    }
    vector<int> find(n + 1, NIL);
    vector<int> finish(n + 1, NIL);
    for (int i = 1; i <= n; i++) {
        DFS(i, a, find, finish);
    }
    for (int i = 1; i <= n; i++) {
        cout << i << " " << find[i] << " " << finish[i] << endl;
    }

    return 0;
}