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<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
vector<bool>seen(1000,false);
vector<pair<int,int>>ans(1000);
vector<int>first_order(1000,10e7),last_order(1000,10e7);
void dfs(const vvll &gura, int v, int& now) {
    first_order[v] = min(first_order[v],now++);

    seen[v] = true; 
    for (auto next_v : gura[v]) { 
        if (seen[next_v]) continue;
        dfs(gura, next_v, now);
    }

    last_order[v] = min(last_order[v],now++);
}
int main(){
    int n;
    cin >> n;
    vvll gura(n);
    for(int i=0;i<n;i++){
        int ww; cin >>ww;
        int w;
        cin >> w;
        for(int j=0;j<w;j++){
            int d;
            cin >> d;
            gura.at(i).push_back(d-1);
        }
    }
    int now = 1;
    for(int i=0;i<n;i++){
        if(seen[i])continue;
    dfs(gura,i,now);
    }
    for(int i=0;i<n;i++){
        cout << i+1<<" "<< first_order[i]<<" "<<last_order[i]<<endl;
    }
}

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

using namespace std;

int n, d[110], f[110], t = 0;
set<int> st;
vector<int> g[110];

void dfs(int m) {
  t++;
  d[m] = t;
  st.erase(m);
  for(int i = 0; i < g[m].size(); i++) {
    if(d[g[m][i]] == -1) {
      dfs(g[m][i]);
    }
  }
  t++;
  f[m] = t;
}

int main() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    int index, k, v;
    cin >> index >> k;
    for(int j = 0; j < k; j++) {
      cin >> v;
      g[index].push_back(v);
    }
    st.insert(index);
    d[index] = -1;
  }
  while(!st.empty()) {
    auto itr = st.begin();
    dfs(*itr);
  }
  for(int i = 0; i < n; i++)
    cout << i+1 << " " << d[i+1] << " " << f[i+1] << endl;

  return 0;
}

C++: #include <cstdio>
#include <vector>
using namespace std;

int cnt=1;

void DFS(int k, vector<vector<int> >& V, vector<pair<int,int> >& time) {
	time[k].first=cnt++;
	for(int i=1; i<=(int)V[k].size(); ++i) {
		if(time[V[k][i]].first==-1) {
			DFS(V[k][i],V,time);
		}
	}
	time[k].second=cnt++;
	return;
}

int main() {
	int i,j;
	int n;
	int u,k;
	vector<vector<int> > V;
	vector<pair<int,int> > time;
	scanf("%d",&n);
	V.resize(n+1);
	time.resize(n+1);

	for(i=1; i<=n; ++i) {
		scanf("%d%d",&u,&k);
		V[u].resize(k);
		time[u]={-1,-1};
		for(j=1; j<=k; ++j) {
			scanf("%d",&V[u][j]);
		}
	}
	DFS(1,V,time);
	for(i=1; i<=n; ++i) {
		printf("%d %d %d\n",i,time[i].first,time[i].second);
	}
	return 0;
}

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

using namespace std;

class Node {
public:
	vector<int> rels;
	int id, len, pos, ts1, ts2;
	Node();
	int next();
};

Node::Node() {
	pos = ts1 = ts2 = 0;
}

int Node::next() {
	if (pos >= len) return -1;
	int next = rels[pos];
	pos++;
	return next;
}


void dfs(int idx, Node **graph, stack<int> *stack, int *time) {
	stack->push(idx);
	graph[idx]->ts1 = ++(*time);
	while (stack->size() > 0) {
		int u = stack->top();
		int v = graph[u]->next();
		if (v != -1) {
			if (graph[v]->ts1 == 0) {
				graph[v]->ts1 = ++(*time);
				stack->push(v);
			}
		}
		else {
			graph[u]->ts2 = ++(*time);
			stack->pop();
		}
	}
}

int main() {
	int n, val, time;
	Node *graph[100];
	stack<int> stack;

	cin >> n;
	
	for (int i = 0; i < n; i++) {
		graph[i] = new Node();
		cin >> graph[i]->id;
		cin >> graph[i]->len;
		for (int j = 0; j < graph[i]->len; j++) {
			cin >> val;
			graph[i]->rels.push_back(val-1);
		}
	}

	time = 0;
	for (int i = 0; i < n; i++) {
		if (graph[i]->ts1 == 0)
			dfs(i, graph, &stack, &time);
	}


	for (int i = 0; i < n; i++) {
		cout << graph[i]->id << " " << graph[i]->ts1 << " " << graph[i]->ts2 << endl;
	}

	for (int i = 0; i < n; i++)
		delete(graph[i]);


	return 0;	
}

C++: #include <bits/stdc++.h>
using namespace std;
#define N 101
int s[N], f[N], tt = 0, n;
int graph[N][N];

void dfs(int node){
    if(s[node] == 0){
        s[node] = ++tt;
    }else return;
    for(int i = 0; i < n; i++){
        if(graph[node][i]) dfs(i);
    }
    f[node] = ++tt;
}

int main(){
    int u, k, val;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++)graph[i][j] = 0;
    }
    for(int i = 0; i < n; i++){
        scanf("%d %d", &u, &k);
        u--;
        for(int j = 0; j < k; j++){
            scanf("%d", &val);
            val--;
            graph[u][val] = 1;
        }
    }
    
    for(int i = 0; i < n; i++)dfs(i);
    for(int i = 0; i < n; i++)printf("%d %d %d\n", i + 1, s[i], f[i]);
}