Go: package main

import "fmt"

type node struct {
	id, d, v int
	adj      []node
}

var n int
var seen []bool
var graph []node

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func dfs(v, t int) int {
	// fmt.Printf("dfs(v %d, t %d) en:\n", v, t)
	seen[v] = true
	graph[v].v = t
	tt := t
	for _, vv := range graph[v].adj {
		if !seen[vv.id] {
			tt = max(tt, dfs(vv.id, tt+1))
		}
	}
	graph[v].d = tt + 1
	// fmt.Printf("dfs(v %d, t %d) ex: d %d\n", v, t, graph[v].d)
	return graph[v].d
}

func main() {
	fmt.Scan(&n)
	graph = make([]node, n+1)
	for i := 1; i <= n; i++ {
		var u, k, v int
		fmt.Scan(&u, &k)
		graph[u].id = u
		// 頂点uはk個の隣接頂点を持っている
		for j := 0; j < k; j++ {
			fmt.Scan(&v)
			var t node
			t.id = v
			graph[u].adj = append(graph[u].adj, t)
		}
	}
	// fmt.Println("n", n, "graph", graph)
	seen = make([]bool, n+1)
	// t := dfs(1, 1)
	v, t := 1, 1
	done := false
	for !done {
		tt := dfs(v, t)
		done = true
		for i := range seen {
			if !seen[i] {
				done = false
				v = graph[i].id
				t = tt
				break
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, graph[i].v, graph[i].d)
	}
}

C++: #include<iostream>
#include<cstdio>
#include<stack>
#include<algorithm>
#include<cstring>
#define white 0
#define balck -1
#define grey 1
using namespace std;

int a[110][110],n;
int color[110];
int t=0;
int ts[105],te[105];

void dfsinit()
{
    for(int i=1;i<=100;i++)
        color[i]=white;
}

void dfsvisit(int u)
{
    color[u]=grey;
    ts[u]=++t;  //搜索
    for(int j=1;j<=n;j++)  //搜索?点
    {
        if(color[j]==white && a[u][j]==1)
        {
           dfsvisit(j);  //深搜
        }
    }
    te[u]=++t;
    color[u]=balck;
}

void dfs()
{
    dfsinit();
    for(int i=1;i<=n;i++)
    {
        if(color[i]==white)
            dfsvisit(i);
    }
}

int main()
{
   int key,d,x;
   t=0;
   memset(a,0,sizeof(a));
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
       scanf("%d%d",&key,&d);
       for(int j=1;j<=d;j++)
       {
        scanf("%d",&x);
        a[key][x]=1;
       }
   }

   dfs();
   for(int i=1;i<=n;i++)
   {
       printf("%d %d %d\n",i,ts[i],te[i]);
   }
   return 0;
}

C++: #include<iostream>
#include<vector>
#include<stack>
#include<climits>

using namespace std;

class Node{
private:
 unsigned long nodeId;
 unsigned long timestampStart;
 unsigned long timestampFinish;
 vector<unsigned long> adjectNode;
 unsigned long checkedNodeNum;

 void stampStart(unsigned long time){
  timestampStart = time;
 };

 void stampFinish(unsigned long time){
  timestampFinish = time;
 };
 

public:
 Node(unsigned long nodeId = 0, unsigned long adjectNodenum = 0)
                  : nodeId(nodeId),
                    timestampStart(0),
                    timestampFinish(0),
                    adjectNode(vector<unsigned long>(adjectNodenum, 0)),
                    checkedNodeNum(0){

 for(unsigned long adjectNode_i = 0; adjectNode_i < adjectNodenum; ++adjectNode_i){
  unsigned long adjectNodeId = 0; cin >> adjectNodeId;

  adjectNode[adjectNode_i] = adjectNodeId;
 } 

 };

 unsigned long getNotCheckedAdjectNode(unsigned long time){
  unsigned long AdjectNodeMax = adjectNode.size();
  if(checkedNodeNum == 0){
   stampStart(time);
  }else if(checkedNodeNum >= AdjectNodeMax){
   stampFinish(time);
   return ULONG_MAX;
  }


  ++checkedNodeNum;

  if(AdjectNodeMax == 0){
   return nodeId;
  }

  return adjectNode[checkedNodeNum-1];

 };

 bool isChecked(){
  if(timestampStart != 0) return true;
  return false;
 }

 void display(){
  cout << nodeId          << " ";
  cout << timestampStart  << " ";
  cout << timestampFinish << endl;
 };


protected:
};

class Graph{
private:
 vector<Node*> graph;

public:
 Graph(unsigned long nodeNum = 0)
                  : graph(vector<Node*>(nodeNum, 0)){
  for(unsigned long node_i = 0; node_i < nodeNum; ++node_i){
   unsigned long nodeId = 0; cin >> nodeId;
   unsigned long adjectNodenum = 0; cin >> adjectNodenum;
   Node* temp_node = new Node(nodeId, adjectNodenum);
   graph[nodeId-1] = temp_node;
  }
 };

 void DepthFirstSearch(){
  unsigned long time = 1;
  stack<unsigned long> checkedNode;
  if(graph[0] == 0) return ;

  checkedNode.push(1);
  while(!checkedNode.empty()){
   unsigned long nowNode = checkedNode.top();
   if(unsigned long nextNode = graph[nowNode-1]->getNotCheckedAdjectNode(time)){
    if(nextNode == ULONG_MAX){
     checkedNode.pop();
    }else if(nextNode == nowNode){
    }else if(graph[nextNode-1]->isChecked()){
     continue;
    }else{
     checkedNode.push(nextNode);
    }
   }
   ++time;
  }

 };

 void display(){
  for(unsigned long node_i = 0, nodeNum = graph.size(); node_i < nodeNum; ++node_i){
   graph[node_i]->display();
  }
 };

protected:

};

int main(){
 unsigned long nodeNum = 0; cin >> nodeNum;

 Graph graph(nodeNum);
 graph.DepthFirstSearch();
 graph.display();

 return 0;
};

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

void DFS(vector<vector<int> > A, vector<int> &d, vector<int> &f, vector<int> &visit, int &t, int v){
	
	visit[v] = 1;
	d[v] = t++;

	for(int i=0;i<A[v].size();i++)
		if((A[v][i] == 1) && (visit[i] == 0))
			DFS(A, d, f, visit, t, i);

	f[v] = t++;
}

int main(){
	int n, u, k, t=1;
	vector<vector<int> > A;
	vector<int> d, f, visit;

	cin>>n;
	A.resize(n);
	d.resize(n);
	f.resize(n);
	for(int i=0;i<n;i++){
		A[i].resize(n);
		visit.push_back(0);
	}

	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			A[i][j] = 0;

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

	for(int i=0;i<n;i++)
		if(!visit[i])
			DFS(A, d, f, visit, t, i);
	
	for(int i=0;i<n;i++)
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;

	return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define find(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

const int MAX_N = 100;
int s[MAX_N + 1], e[MAX_N + 1];
int N, t = 1;
vector<vector<int>> g(MAX_N + 1);

void dfs(int i) {
  if (s[i] > 0) return;
  // cout << "i = " << i << ", t = " << t << endl;

  s[i] = t++;
  for (int j = 0; j < g[i].size(); j++) {
    dfs(g[i][j]);
  }
  e[i] = t++;
}

void dfs() {
  for (int i = 1; i <= N; i++) {
    if (s[i] > 0) continue;
    dfs(i);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  cin >> N;
  for (int i = 0; i < N; i++) {
    int u; cin >> u;
    int k; cin >> k;
    for (int ki = 0; ki < k; ki++) {
      int tmp; cin >> tmp;
      g[u].push_back(tmp);
    }
    sort(g[u])
  }

  memset(s, 0, sizeof(s));
  memset(e, 0, sizeof(e));

  // outl("-------------")
  // for (int i = 1; i <= N; i++) {
  //   cout << i << " ";
  //   for (int j = 0; j < g[i].size(); j++) {
  //     cout << g[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  // outl("-------------")

  dfs();

  for (int i = 1; i <= N; i++) {
    cout << i << " " << s[i] << " " << e[i] << endl;
  }
}