Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nVerts := scanInt(sc)
	graph := make([][]int, nVerts+1)

	for i := 0; i < nVerts; i++ {
		u := scanInt(sc)
		nDegrees := scanInt(sc)

		graph[u] = make([]int, nDegrees)
		for d := 0; d < nDegrees; d++ {
			graph[u][d] = scanInt(sc)
		}
	}

	starts := make([]int, nVerts+1)
	ends := make([]int, nVerts+1)
	time := 1

	var dfs func(u int)
	dfs = func(u int) {
		if starts[u] > 0 {
			return
		}

		starts[u] = time
		time += 1

		for _, v := range graph[u] {
			dfs(v)
		}

		ends[u] = time
		time += 1
	}

	for i := 1; i <= nVerts; i++ {
		dfs(i)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= nVerts; i++ {
		fmt.Fprintf(w, "%d %d %d\n", i, starts[i], ends[i])
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

using namespace std;

int main(){
    stack<int> st;
    int n;
    cin >> n;
    int d[n] = {};
    int f[n] = {};
    int vnum[n][2] = {};
    bool vflag[n] = {};
    int tmp2;
    int num;
    vector<vector<int>> vertex;
    vector<int> tmp;
    for(int i=0;i<n;i++){
        cin >> num;
        cin >> num;
        vnum[i][0] = num;
        for(int j=0;j<num;j++){
            cin >> tmp2;
            tmp.push_back(tmp2);
        }
        vertex.push_back(tmp);
        tmp.clear();
    }
    int cnt = 1;
    bool check;
    int s;
    st.push(0);
    do{
        s = st.top();

        if(((vnum[s][0]==0) && d[s]==0) || (s==vertex[s][vnum[s][1]]-1)){
            vflag[s] = true;
            d[s] = cnt++;
            f[s] = cnt++;
            st.pop();
        }else if(vnum[s][0]==vnum[s][1]){
            vflag[s] = true;
            f[s] = cnt++;
            st.pop();
        }else if((vflag[vertex[s][vnum[s][1]]-1]) && (d[s]==0)){
            if(vnum[s][0]-vnum[s][1]==1){
                vflag[s] = true;
                d[s] = cnt++;
                f[s] = cnt++;
                st.pop();
            }else{
                vnum[s][1]++;
            }
        }else if(vflag[vertex[s][vnum[s][1]]-1]){
            vflag[s] = true;
            f[s] = cnt++;
            st.pop();
        }else if(vflag[s]){
            st.push(vertex[s][vnum[s][1]++] - 1);
        }else{
            if(d[s]==0){
                d[s] = cnt++;
            }
            st.push(vertex[s][vnum[s][1]++] - 1);
            if(vnum[s][0]==vnum[s][1]){
                vflag[s] = true;
            }
            if(vflag[vertex[s][vnum[s][1]]-1]){
                f[s] = cnt++;
                st.pop();
            }
        }
        check = !st.empty();
        if(!check){
            for(int i=0;i<n;i++){
                if(vflag[i]==false){
                    check = true;
                    st.push(i);
                    break;
                }
            }
        }
    }while(check);

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

C++: #include <stdio.h>
#include <stack>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

using namespace std;

int n;
int M[N][N]; // ??£??\??????
int d[N]; // ????????????
int f[N]; // ????????????
int color[N]; // ?¨??????¶???
int nt[N];
int tt = 0; // ??????


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


void dfs_visit(int r)
{
    int i;
    for (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;
        }        
    }
}

// ?????°ver
void dfs_visit_r(int r)
{
    int v;
    color[r] = GRAY;
    d[r] = ++tt;
    for (v = 0; v < n; v++) {
        if (M[r][v] == 0) continue;
        if (color[v] == WHITE) dfs_visit_r(v);
    }
    color[r] = BLACK;
    f[r] = ++tt;
}


void dfs()
{
    int i;
    for (i = 0; i < n; i++) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;
    
    for (i = 0; i < n; i++) {
        if (color[i] == WHITE) {
            //dfs_visit(i);
            dfs_visit_r(i);
        }
    }   
     
    for (i = 0; i < n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
}


int main()
{
    scanf("%d", &n);
    int i, j;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }
    
    // input graph
    int u, k, v;
    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        for (j = 0; j < k; j++) {
            scanf("%d", &v);
            M[u-1][v-1] = 1;
        }
    }
    
    dfs();
    
    return 0;
}

C++: #if 0

#endif
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <queue>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
using ll = long long;
ll ll_max = numeric_limits<ll>::max();
ll ll_min = numeric_limits<ll>::min();
int int_max = numeric_limits<int>::max();
int int_min = numeric_limits<int>::min();
int N, id, C, to;
vector<int> V[100];
int t = 0;
int visit[100][2] = {};
void dfs(int cur) {
    t += 1;
    visit[cur][0] = t;
    for (auto v : V[cur]) {
        if (visit[v][0] == 0) dfs(v);
    }
    t += 1;
    visit[cur][1] = t;
} 


int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    rep(n, N) {
        cin >> id >> C;
        rep(c, C) {
            cin >> to;
            V[n].push_back(to - 1);
        }
    }
    
    rep(n, N) {
        if (visit[n][0] == 0)
            dfs(n);
    }
        

    rep(n, N) cout << n + 1 << " " << visit[n][0] << " " << visit[n][1] << endl;

    return 0;
}

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 color[N], nt[N], M[N][N], d[N], f[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[v] = BLACK;
	    	f[u] == ++tt; 
	    }
	} 
}


void dfs() {
   for(int i = 0; i < n; i++) {
   	   color[i] = WHITE;
       nt[i] = 0; 
   }
   tt = 0;
   
   for(int i = 0; i < n; i++) {
   	   if(color[i] = WHITE) {
   	   	   dfs_visit(i);
   	   }
   }
   
   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;
	
}