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

	timer := 1
	startNode := 1
	for {
		visit(startNode, &timer, childrenMap, timeRecordMap)
		startNode = findStartNode(childrenMap, timeRecordMap)
		if startNode < 0 {
			break
		}
	}
	for k, v := range timeRecordMap {
		fmt.Printf("%d %d %d\n", k+1, v.discoverTime, v.finishTime)
	}
}

func findStartNode(childrenMap [][]int, timeRecordMap []TimeRecord) int {
	x := -1
	for node, timeRecord := range timeRecordMap {
		if timeRecord.discoverTime < 0 {
			x = node + 1
			break
		}
	}
	return x
}

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