Go: package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}

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 = cur+1; 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);
	  list[x-1].push_back(k-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);
  for(int i = 0;i < np; i++){
    cout << i+1 <<" "<<d[i]+1 <<" "<<f[i]+1<<endl;
  }


  return 0;
}

C++: #include <bits/stdc++.h>
#define pb push_back
using namespace std;

int num = 1;
bool visited[1000];
vector<int> v[1000], seq[1000];
void dfs(int k){
    seq[k].pb(num++);
    if(visited[k]) return;
    visited[k] = 1;
    for (auto t : v[k]){
        if(visited[t]) continue;
        dfs(t);
    }
    seq[k].pb(num++); return;

}
int main(){
    int n; cin >> n;
    memset(visited, 0, sizeof(visited));
    for (int i = 0; i < n; i++){
        int x, y, z; cin >> x >> y;
        for (int j = 0; j < y; j++){
            cin >> z; v[x].pb(z);
        }
    }
    for(int i = 1; i <= n; i++)
        sort(v[i].begin(), v[i].end());
    for(int i = 1; i <= n; i++)
        if(!visited[i])
            dfs(i);
    for (int i = 1; i <= n; i++){
        cout << i << ' ';
        for (auto k : seq[i])
        cout << k << ' ';
        cout << '\n';
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int n, t = 0;
vector<set<int>> g;
vi d, f;

void dfs(int v) {
  t++;
  d[v] = t;
  for(auto i : g[v])
    if(d[i] == 0) dfs(i);
  t++;
  f[v] = t;
}

int main() {
  cin >> n;
  d = vi(n, 0);
  f = vi(n, 0);
  g = vector<set<int>>(n);
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    rep(j, k) {
      int v;
      cin >> v;
      v--;
      g[i].insert(v);
    }
  }
  rep(i, n) if(d[i] == 0) dfs(i);
  rep(i, n) printf("%d %d %d\n", i + 1, d[i], f[i]);
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

vi d, f;
vector<bool> r;
int t;

void dfs(vvi &g, int u) {	
	r[u] = true;
	d[u] = t++;
	for (int v : g[u]) {
		if (r[v]) continue;
		dfs(g, v);
	}
	f[u] = t++;
}

int main() {
	int n; cin >> n;
	vvi g(n + 1);
	rep(j, n) {
		int u, k; cin >> u >> k;
		rep(j, k) {
			int vj; cin >> vj;
			g[u].push_back(vj);
		}
	}

	r.assign(n + 1, false);
	d.assign(n + 1, 0); f.assign(n + 1, 0);
	t = 1;
	rep2(i, 1, n + 1) if (!r[i]) dfs(g, i);
	/*
	dbvv(g);
	dbv(d);
	dbv(f);
	*/
	rep2(i, 1, n + 1) {
		printf("%d %d %d\n", i, d[i], f[i]);
	}
}

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

int a[101][101];
int n = 0;
int found[101];
int ended[101];
int aaa(int i, int time);

int main() {
  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 101; j++)
	  a[i][j] = 0;
  int u, k, v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
	for (int j = 0; j < k; j++) {
	  cin >> v;
	  a[u][v] = 1;
	  }
	 }
int time = 0;
for (int i = 0; i < 101; i++){
  found[i] = 0;
  ended[i] = 0;
  }
for (int i = 0; i < n+1; i++) {
  if(found[i] > 0)
    continue;
  time++;
  found[i]=time;
  time=aaa(i,time);
  ended[i]=time;
  }
  
for (int i = 1; i < n+1; i++) {
 cout << i << ' ' << found[i] << ' ' << ended[i] << endl;
 }
 
}
 
int aaa(int i, int time) {
  for (int k = 1; k < n+1; k++) {
    if (a[i][k] == 1 && found[k] == 0) {
	  time++;
	  found[k] = time;
	  time = aaa(k,time);
	  ended[k] = time;
	  }
	 }
	time++;
	return time;
	}

C++: #include <iostream>

using namespace std;
int n,u,k,v,**M,flag[100],s_time[100],f_time[100];
void creat()
{
    cin>>n;
  M=new int*[n];
  for(int i=0;i<n;i++)
    {
      M[i]=new int[n];
      flag[i]=0;
      for(int j=0;j<n;j++)
	M[i][j]=0;
    }
  int count=0;
  while(count<n)
    {
      count++;
      cin>>u>>k;
      for(int i=0;i<k;i++)
	{
	  cin>>v;
	  M[u-1][v-1]=1;
	}
    }
    /*for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)
      cout<<M[i][j]<<' ';
    cout<<endl;
  }*/
}
int time;
void dfs(int cur) {
    time += 1;
    s_time[cur]=time;
    //cout << "visiting " << cur+1 << ' ' << time << endl;
    flag[cur]=1;
    for (int dst=0;dst<n;dst++) {
            if (M[cur][dst]&&!flag[dst]) {
                dfs(dst);
            }
    }
    time += 1;
    f_time[cur]=time;
}
int main()
{
    time=0;
    creat();
    for(int i=0;i<n;i++)
    {
        if(!flag[i])
            dfs(i);
    }
    for(int i=0;i<n;i++)
    {
        cout<<i+1<<' '<<s_time[i]<<' '<<f_time[i]<<endl;
    }
    delete M;
    return 0;
}