Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,step=0,fdepth[105],sdepth[105];
bool visit[105],c[105][105];
void dfs(int node){
    step++;
    fdepth[node]=step;
    for(int i=1;i<=n;i++)
        if(!visit[i]&&c[node][i]){
            visit[i]=1;
            dfs(i);
        }
    step++;
    sdepth[node]=step;
}
int allvisit(int node){
    for(int i=1;i<=n;i++)
        if(!visit[i])
            return i;
    return 0;
}
int main(){
    ios_base::sync_with_stdio(0);
    //cin.tie(0);
    while(cin>>n){
        memset(fdepth,0,sizeof(fdepth));
        memset(sdepth,0,sizeof(sdepth));
        memset(c,0,sizeof(c));
        memset(visit,0,sizeof(visit));
        int parent,num,son;
        for(int i=0;i<n;i++){
            cin>>parent>>num;
            while(num--){
                cin>>son;
                c[parent][son]=1;
            }
        }
        step=0;
        visit[1]=1;
        dfs(1);
        while(allvisit(1)){
            step=0;
            dfs(allvisit(1));
        }
        for(int i=1;i<=n;i++)
            cout<<i<<' '<<fdepth[i]<<' '<<sdepth[i]<<'\n';
    }
    return 0;
}

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