Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

C++: #include <bits/stdc++.h>
using namespace std;

int n,t;
vector<vector<int>> M(101,vector<int>(101,0));
vector<int> color(101,0);
vector<int> d(101,0),f(101,0);

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

int main(){
    cin>>n;
    for(int i=1;i<n+1;i++){
        int a,b,k;
        cin>>a>>k;
        for(int j=0;j<k;j++){
            cin>>b;
            M[a][b]=1;
        }
    }

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

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

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

struct Node {
	int ID;
	int d;
	int f;
	bool visited;
	bool operator<(const Node& rhs) {return this->ID < rhs.ID;}
	bool operator>(const Node& rhs) {return this->ID > rhs.ID;}
	bool operator<=(const Node& rhs) {return this->ID <= rhs.ID;}
	bool operator>=(const Node& rhs) {return this->ID >= rhs.ID;}
	bool operator==(const Node& rhs) {return this->ID == rhs.ID;}
	bool operator!=(const Node& rhs) {return this->ID != rhs.ID;}
};

int step = 1;

void DFS(std::vector<int>* adjlist, Node* nodes, int v)
{
	nodes[v].visited = true;
	nodes[v].d = step;
	step++;
	
	for (int i=0; i<adjlist[v].size(); i++) {
		int id = adjlist[v][i];
		if (!nodes[id].visited) DFS(adjlist, nodes, id);
	}
	
	nodes[v].f = step;
	step++;
}

int main()
{
	int n; std::cin >> n;
	
	std::vector<int>* adjlist = new std::vector<int>[n];
	Node* nodes = new Node[n];
	
	for (int i=0; i<n; i++) nodes[i].visited = false;
	
	for (int i=0; i<n; i++) {
		int x;
		int deg;
		std::cin >> x >> deg;
		nodes[i].ID = x-1;
		for (int j=0; j<deg; j++) {
			int y;
			std::cin >> y;
			adjlist[x-1].push_back(y-1);
		}
	}
	
	std::sort(nodes, nodes + n);
	
	for (int i=0; i<n; i++) {
		if (!nodes[i].visited) DFS(adjlist, nodes, i);
	}
	
	for (int i=0; i<n; i++) {
		std::cout << nodes[i].ID + 1 << " " << nodes[i].d << " " << nodes[i].f << std::endl;
	}
	
	delete[] adjlist;
	delete[] nodes;
	
	return 0;
}

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

using namespace std;

int curTime = 1;
void dfs(int cur, const vector<vector<bool> >& a, vector<int>& d, vector<int>& f, vector<bool>& visited){
  visited[cur] = true;
  d[cur] = curTime;
  curTime++;
  cerr << "visiting [" << cur << "], time = " << curTime << endl;

  for(int dst = 1; dst <= a.size(); dst++){
    if(a[cur][dst] && !visited[dst]) {// cur????????¶??????????????????????????????
      dfs(dst, a, d, f, visited);
    }
  }
  f[cur] = curTime;
  curTime++;
  return;
}

int main(){
  int n;
  cin >> n;
  vector<vector<bool> > a(n+1, vector<bool>(n+1, false));
  for(int i = 1; i <= n; i++){
    int u;
    cin >> u;
    int k;
    cin >> k;
    for(int j = 0; j < k; j++){
      int v;
      cin >> v;
      a[i][v] = true;
    }
  }

  vector<bool> visited(n+1, false);
  vector<int> d(n+1), f(n+1);

  dfs(1, a, d, f, visited);

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

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


using namespace std;

int timecount = 0;

void dfs(int cur, int u, bool* visited, int* timearray, int* timearray_end, unordered_map<int, vector<int> > mymap);

int main(){
  int u, i, id, k, j;
  cin >> u;
  unordered_map<int, vector<int> > mymap;

  for (i = 0; i < u; ++i){
    cin >> id >> k;
    vector<int> points;
    for (j = 0; j < k; ++j){
      int a;
      cin >> a;
      points.push_back(a);
    }
    mymap[id] = points;
  }
  
  bool visited[u+1];
  for (j = 1; j <= u; ++j){
    visited[j] = false;
  }
  visited[1] = true;

  int timearray[u+1];
  for (j = 1; j <= u; ++j){
    timearray[j] = 0;
  }
  int timearray_end[u+1];
  for (j = 1; j <= u; ++j){
    timearray_end[j] = 0;
  }

  dfs(1, u, visited, timearray, timearray_end, mymap);

  for (j = 1; j <= u; ++j){
    cout << j << " " << timearray[j] << " " << timearray_end[j]<< endl;
  }

}

void dfs(int cur, int u, bool* visited, int* timearray, int* timearray_end, unordered_map<int, vector<int> > mymap){
  timecount++;
  timearray[cur] = timecount;

  for(int i = 1; i <= u; ++i){
    
    if((i!=cur)&&(find(mymap[cur].begin(), mymap[cur].end(), i) != mymap[cur].end())&&(!visited[i])){
      visited[i] = true;
      dfs(i, u, visited, timearray, timearray_end, mymap);
    }
  }
  timecount++;

  timearray_end[cur] = timecount;
}

C++: #include <bits/stdc++.h>
using namespace std;

int n;
int graph[100][100];
int d[100];
int f[100];

// 時刻
int cnt;

// 0:未探索 1:探索中 2:探索終わり
int visited[100];

void dfs(int i) {
  // 探索開始
  visited[i] = 1;
  d[i] = ++cnt;
  for (int j = 0; j < n; j++) {
    if (graph[i][j] == 0) {
      continue;
    }
    // 再帰
    if (visited[j] == 0) {
      dfs(j);
    }
  }
  visited[i] = 2;
  f[i] = ++cnt;
}

int main() {

  cin >> n;

  // 各変数を初期化
  cnt = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      graph[i][j] = 0;
    }
    visited[i] = 0;
    d[i] = 0;
    f[i] = 0;
  }

  // 入力を受け取る
  for(int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int v;
      cin >> v;
      graph[u - 1][v - 1] = 1;
    }
  }

  // 探索
  for (int i = 0; i < n; i++) {
    if(visited[i] == 0) {
      dfs(i);
    }
  }

  // 探索結果を出力
  for (int i = 0; i < n; i++) {
    cout << i + 1 << " " << d[i] << " " << f[i] << endl;
  }

  return 0;

}