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<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, tt;
int M[N][N], color[N], d[N], f[N], nt[N]; 

void dfs_visit(int r) {
    for(int i = 0; i < n; i++) {
        nt[i] = 0;
	}
	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;
	while(!S.empty()) {
		int u = S.top();
		int v;
		for(v = 0; v < n; v++) {
			if(M[u][v] == 0) continue;
			if(color[v] != WHITE) continue;
			break; 
		}
		if(v != n) {
			if(color[v] == WHITE) {
			   color[v] = GRAY;
			   d[v] = ++tt;
			   S.push(v); 	
		    }
		} 
		for(v = 0; v < n; v++) {
			if(M[u][v] == 0) continue;
			break; 
		}
		if(v == n){
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


void dfs() {
	for(int i = 0; i < n; i++) {
	     color[i] = WHITE;
	}
	tt = 0;
		
	for(int u = 0; u < n; u++) {
		if(color[u]) dfs_visit(u);
	}

	
	for(int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;	
	}
}

int main() {
	int k , u, v;
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}
	
	for(int i = 0; i < n; i++) {
		cin >> u >> k;
	    u--;
	    for(int i = 0; i < k; i++) {
	        cin >> v;
	        v--;
		   M[u][v] = 1; 
     	}
	} 
	
	dfs();
	
	return 0;
}

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

vector<vector<int>> v;
vector<int> d, f;

int t = 0;
void dfs(int x){
  d[x] = ++t;
  for(int i=0; i<v[x].size(); ++i){
    if(v[x][i] == 1 && d[i] == 0){
      dfs(i);
    }
  }
  f[x] = ++t;
}

int main(){
  int n; cin >> n;

  v.resize(n);
  d.resize(n);
  f.resize(n);

  for(int i=0; i<n; ++i) v[i].resize(n);

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

  for(int i=0; i<n; ++i){
    if(d[i] == 0) dfs(i);
  }

  for(int i=0; i<n; ++i){
      cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
}

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

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u) {
    for(int v=nt[u]; v<n; v++) {
      nt[u] = v + 1;
      if(M[u][v]) return v;
    }
    return -1;
}

void dfs_visit(int r) {
    for(int i=0; i<n; i++) nt[i] = 0;
    
    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;
    
    while(!S.empty()) {
        int u = S.top();
        int v = next(u);
        if(v != -1) {
            if(color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs() {
    for(int i=0; i<n; i++) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;
    
    for(int u=0; u<n; u++) {
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(int i=0; i<n; i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int u, k, v;
    
    cin >> n;
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) M[i][j] = 0;
    }
    
    for(int i=0; i<n; i++) {
        cin >> u >> k;
        u--;
        for(int j=0; j<k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
    
    return 0;
}

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

int n, t;
int A[101][101];
int d[101], f[101];

void depthFirstSearch(int r) {
	d[r] = ++t;
	for (int i = 1; i <= n; i++) {
		if (A[r][i] == 1 && d[i] == 0) depthFirstSearch(i);
	}
	f[r] = ++t;
	return;
}

int main() {
	int u, v, l;
	t = 0;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		d[i] = f[i] = 0;
	}

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

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

	for (int i = 1; i <= n; i++) {
		if (d[i] == 0) depthFirstSearch(i);
	}

	for (int i = 1; i <= n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

constexpr int N = 100;
enum Color { White, Gray, Black };
vector<vi> M(N, vi(N, 0));
vi d(N), f(N), nt(N, 0);
vector<Color> color(N, White);

int next(int u) {
  FOR(v, nt[u], nt.size()) {
    nt[u] = v + 1;
    if (M[u][v]) return v;
  }
  return -1;
}

void dfs_visit(int r, int &tt) {
  fill(nt.begin(), nt.end(), 0);
  stack<int> S;
  S.push(r);
  color[r] = Gray;
  d[r] = ++tt;

  while (!S.empty()) {
    auto u = S.top();
    auto v = next(u);
    if (v != -1) {
      if (color[v] == White) {
        color[v] = Gray;
        d[v] = ++tt;
        S.push(v);
      }
    } else {
      S.pop();
      color[u] = Black;
      f[u] = ++tt;
    }
  }
}

void dfs(int n, int &tt) {
  REP(u, d.size()) {
    if (color[u] == White) dfs_visit(u, tt);
  }
  REP(i, d.size()) cout << i + 1 << " " << d[i] << " " << f[i] << endl;
}

int main() {
  int n, u, k, v;
  cin >> n;
  REP(i, n) {
    cin >> u >> k;
    REP(j, k) {
      cin >> v;
      M[u - 1][v - 1] = 1;
    }
  }
  int tt = 0;
  d.resize(n);
  f.resize(n);
  nt.resize(n);
  dfs(n, tt);
}