Go: package main

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

type TimeRecord struct {
	discoverTime int
	finishTime   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	timeRecordMap := make([]TimeRecord, n)
	childrenMap := make([][]int, n)
	for i := 1; i <= n; i++ {
		node, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		timeRecordMap[node-1] = TimeRecord{-1, -1}

		childNum, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		childrenMap[node-1] = make([]int, childNum)
		for j := 0; j < childNum; j++ {
			child, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			childrenMap[node-1][j] = child
		}
	}

	// TODO: always start with 1?
	timer := 1
	visit(1, &timer, childrenMap, timeRecordMap)
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func visit(currentNode int, timer *int, childrenMap [][]int, timeRecordMap []TimeRecord) {
	if timeRecordMap[currentNode-1].discoverTime > 0 {
		return
	}
	children := childrenMap[currentNode-1]
	timeRecordMap[currentNode-1] = TimeRecord{*timer, timeRecordMap[currentNode-1].finishTime}
	(*timer)++
	for i := 0; i < len(children); i++ {
		visit(children[i], timer, childrenMap, timeRecordMap)
	}
	timeRecordMap[currentNode-1] = TimeRecord{timeRecordMap[currentNode-1].discoverTime, *timer}
	(*timer)++
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

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;

}