Go: package main

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

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

	nVerts := scanInt(sc)
	graph := make([][]int, nVerts+1)

	for i := 0; i < nVerts; i++ {
		u := scanInt(sc)
		nDegrees := scanInt(sc)

		graph[u] = make([]int, nDegrees)
		for d := 0; d < nDegrees; d++ {
			graph[u][d] = scanInt(sc)
		}
	}

	starts := make([]int, nVerts+1)
	ends := make([]int, nVerts+1)
	time := 1

	var dfs func(u int)
	dfs = func(u int) {
		if starts[u] > 0 {
			return
		}

		starts[u] = time
		time += 1

		for _, v := range graph[u] {
			dfs(v)
		}

		ends[u] = time
		time += 1
	}

	for i := 1; i <= nVerts; i++ {
		dfs(i)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= nVerts; i++ {
		fmt.Fprintf(w, "%d %d %d\n", i, starts[i], ends[i])
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

C++: #include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

// u に隣接する v を番号順に取得
int next(int u) {
  for ( int v = nt[u]; v < n; v++ ) {
    nt[u] = v + 1;
    if ( M[u][v] ) return v;
  }
  return -1;
}

// スタックを用いた深さ優先探索
void dfs_visit(int r) {
  for ( int i = 0; i < n; i++ ) nt[i] = 0;

  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  d[r] = ++tt;

  while ( !S.empty() ) {
    int u = S.top();
    int v = next(u);
    if ( v != -1 ) {
      if ( color[v] == WHITE ) {
        color[v] = GRAY;
        d[v] = ++tt;
        S.push(v);
      }
    } else {
      S.pop();
      color[u] = BLACK;
      f[u] = ++tt;
    }
  }
}

void dfs() {
  // 初期化
  for ( int i = 0; i < n; i++ ) {
    color[i] = WHITE;
    nt[i] = 0;
  }
  tt = 0;

  // 未訪問の u を始点として深さ優先探索
  for ( int u = 0; u < n; u++ )
    if ( color[u] == WHITE ) dfs_visit(u);
  for ( int i = 0; i < n; i++ )
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
}

int main() {
  int u,  k, v;

  cin >> n;
  for ( int i = 0; i < n; i++ )
    for ( int j = 0; j < n; j++ ) M[i][j] = 0;

  for ( int i = 0; i < n; i++ ) {
    cin >> u >> k;
    u--;
    for ( int j = 0; j < n; j++ ) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

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;

}