Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) doesAllAdjsVisited(vertices []vertex) bool {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return false
		}
	}
	return true
}

func (v *vertex) isFirstVisit() bool {
	return v.firstVisitAt == 0
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func (v *vertex) nextVertex(vertices []vertex) (vertexId, error) {
	for _, vId := range v.adjs {
		adj := vertices[vId-1]
		if !adj.isVisited() {
			return vId, nil
		}
	}
	return vertexId(-1), fmt.Errorf("illegal")
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	timestamp = timestamp + 1
	currentVertex := &vertices[currentId-1]
	if currentVertex.isFirstVisit() {
		currentVertex.firstVisitAt = timestamp
	}
	for !currentVertex.doesAllAdjsVisited(vertices) {
		nextVertexId, _ := currentVertex.nextVertex(vertices)
		timestamp = dfs(nextVertexId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

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

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

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	dfs(vertexId(1), 0, vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

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

using namespace std;
int cnt = 1;

struct Edge{
	int to;
};

void DFS_visit(int top, vector<vector<Edge>>& G, vector<vector<int>>& timestump)
{
	int next;
	timestump[top][0] = cnt++;
	Label:
	if(G[top].empty()){
		timestump[top][1] = cnt++;
	}else{
		next = G[top].begin()->to - 1;
		G[top].erase(G[top].begin());
		if(timestump[next][0] == 0){
			DFS_visit(next, G, timestump);
			goto Label;
		}else{
			goto Label;
		}
	}
}

void DFS(vector<vector<Edge>>& G)
{
	vector<vector<int>> timestump;
	timestump = vector<vector<int>>(G.size(), vector<int>(2, 0));

	for(int i = 0; i < G.size(); i++){
		if(timestump[i][0] == 0){
			DFS_visit(i, G, timestump);
		}
	}

	for(int i = 0; i < G.size(); i++){
		cout << i + 1 << " " << timestump[i][0] << " " << timestump[i][1] << endl;
	}
}

int main(void)
{
	int num;
	cin >> num;

	vector<vector<Edge>> AdjList(num);
	for(int i = 0; i < num; i++){
		int u, k;
		cin >> u >> k;
		for(int j = 0; j < k; j++){
			int v;
			cin >> v;
			AdjList[i].push_back(Edge{v});
		}
	}

	DFS(AdjList);
	return 0;
}

C++: #include <utility>
#include <algorithm>
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector <int> m[103];
int kakunin[103]={0};
int d[103];
int f[103];
int cnt=0;
void dfs(int num){
    d[num]=cnt++;
    for(int i=0;i<m[num].size();i++){
        if(kakunin[m[num][i]]==0){kakunin[m[num][i]]=1;dfs(m[num][i]);}}
    f[num]=cnt++;
}
int main() {
    int n,a,tmp,id;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>id;
        cin>>a;
        for(int j=0;j<a;j++){
            scanf("%d",&tmp);
            m[id].push_back(tmp);
        }
    }
    for(int i=0;i<102;i++){m[0].push_back(i);}
    dfs(0);
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<d[i]-1<<" "<<f[i]-1<<endl;}
}

C++: #include<iostream>
#include<map>
#include<cstdio>
#include<vector>
#include<stack>
using namespace std;
typedef pair<int,int> P;

int nextPos();

int n;
vector<int>vec[105];
stack<int>st;
map<int,P>mp;

int main(){
  //ios_base::sync_with_stdio(false);
  int a,m,c;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a >> m;
    for(int j=0;j<m;j++){
      cin >> c;
      vec[a].push_back(c);
    }
  }

  int count = 1;
  while(1){
    int next = nextPos();
    if(next == 0) break;
    st.push(next);
    mp[next].first = count;
    count++;
    while(!st.empty()){

      bool flag=false;
      for(int i=0;i<vec[next].size();i++){
	int temp = vec[next][i];
	if(mp[temp].first == 0){
	  st.push(temp);
	  next = temp;
	  mp[temp].first = count;
	  count++;
	  flag = true;
	  break;
	}
      }

      if(!flag){ //いくところが無かったら
	mp[next].second = count;
	count++;
	st.pop();

	while(!st.empty()){
	  int point = st.top();
	  
	  flag = false;
	  for(int i=0;i<vec[point].size();i++){
	    int temp2 = vec[point][i];
	    if(mp[temp2].first == 0){
	      next = temp2;
	      st.push(next);
	      mp[next].first = count;
	      count++;
	      flag = true;
	      break;
	    }
	  }

	  if(flag) break;
	  else{
	    st.pop();
	    mp[point].second = count;
	    count++;
	  }
	}
      }
    }
  }

  for(int i=1;i<=n;i++){
    cout << i << " " << mp[i].first << " " << mp[i].second << endl;
  }

  return 0;
}

int nextPos(){
  int a=0;

  for(int i=1;i<=n;i++){
    if(mp[i].first == 0){
      a = i;
      break;
    }
  }

  return(a);
}

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

int time1 = 0;
int a[110][110] = {};
int d[110] = {};
int f[110] = {};
int n;
int p;

void dfs(int cur){
  if(d[cur]==0){
    d[cur] = time1;
  }
  time1 += 1;

  for(int dst=1;dst<=n;dst++){
    if(a[cur][dst]==1&&d[dst]==0){
      dfs(dst);
      a[cur][dst]=2;
    }
  }
  f[cur] = time1;
  time1 += 1;
  for(int k=1;k<=n;k++){
    if(a[k][cur]==2){
      a[k][cur]=1;
      p+=1;
      dfs(k);
    }
  }
  if(p==0){
    for(int k=0;k<=n;k++){
      if(d[k]==0){
	dfs(k);
      }
    }
  }
}

int main(){
  cin>>n;
  for(int i=1;i<=n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v;
      cin>>v;
      a[i][v]=1;
    }
  }
  time1 += 1;
  dfs(1);
  for(int k=0;k<=n;k++){
    cout<<k<<" "<<d[k]<<" "<<f[k]<<endl;
  }
}

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;
}