Go: package main

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

type vertexId int

type vertex struct {
	id vertexId
	firstVisitAt int
	finishVisitAt int
	adjs []vertexId
}

func createVertex(id int, adjsInt []int) vertex {
	adjs := make([]vertexId, len(adjsInt))
	for i := 0; i < len(adjs); i++ {
		adjs[i] = vertexId(adjsInt[i])
	}
	return vertex{
		id: vertexId(id),
		firstVisitAt: 0,
		finishVisitAt: 0,
		adjs: adjs,
	}
}

func (v *vertex) isVisited() bool {
	return v.firstVisitAt > 0
}

func dfs(currentId vertexId, timestamp int, vertices []vertex) int {
	currentVertex := &vertices[currentId-1]
	if currentVertex.isVisited() {
		return timestamp
	}
	timestamp = timestamp + 1
	currentVertex.firstVisitAt = timestamp
	for _, adjId := range currentVertex.adjs {
		timestamp = dfs(adjId, timestamp, vertices)
	}
	timestamp = timestamp + 1
	currentVertex.finishVisitAt = timestamp
	return timestamp
}

func solveDfs(vertices []vertex) {
	timestamp := 0
	for {
		vid := vertexId(-1)
		for i := 0; i < len(vertices); i++ {
			if !vertices[i].isVisited() {
				vid = vertexId(i+1)
				break
			}
		}
		if vid > 0 {
			timestamp = dfs(vid, timestamp, vertices)
		} else {
			break
		}
	}
}

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

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	vertices := make([]vertex, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjN, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		adjs := make([]int, adjN)
		for j := 0; j < adjN; j++ {
			adjId, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			adjs[j] = adjId
		}
		vertices[i] = createVertex(id, adjs)
	}

	solveDfs(vertices)

	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", vertices[i].id, vertices[i].firstVisitAt, vertices[i].finishVisitAt)
	}
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}

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

using namespace std;

int N,k[1000];
int v[1000][1000];
int found[1000] = {0},ended[1000] = {0};
int keep;
int checking=0;

void dfs(int cur);

int main() {
	cin >> N;
	for(int i=1;i<N+1;i++) {
		cin >> keep >> k[i];
		for(int j=1;j<k[i]+1;j++) {
			cin >> v[i][j];

		}
	}
	dfs(1);
	while(true) {
		cout << "processing..." << endl;
		bool flag = false;
		int key = 1;
		for(int i=1;i<N+1;i++) {
			if(found[i] == 0) {
				flag = true;
				key = i;
				break;
			}
		}
		if(flag) {
			dfs(key);
		} else {
			break;
		}
	}
	
	
	for(int i=1;i<N+1;i++) {
		cout << i << " " << found[i] << " " << ended[i] << endl;
	}
	

}

void dfs(int cur) {
	int loopcount=0;
	cout << "process ended" << endl;
	if(!found[cur]) {
		checking++;
		cerr << "visiting: " << cur << " " << "time: " << checking << endl;
		found[cur] = checking;
	}
	for(int dst=1;dst<N+1;dst++) {
		loopcount++;
		bool flag = false;
		for(int i=1;i<k[cur]+1;i++) {
			if(v[cur][i] == dst) flag = true;
		}
		if((flag) && (dst != cur)) dfs(dst);
	}
	if(!ended[cur]) {
		checking++;
		cerr << "ended: " << cur << " " << "time: " << checking << endl;
		ended[cur] = checking;
	}
}

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

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

int n,a[S][S];
int cnd[S],d[S],f[S],T=0;
int nt[S];

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

void visit(int r){
    for(int i=0;i<n;i++)nt[i]=0;
    stack<int>st;
    st.push(r);
    cnd[r]=GRAY;
    d[r]=++T;

    while(!st.empty()){
        int u=st.top();
        int v=next(u);
        if(v!=-1){
            if(cnd[v]==WHITE){
                cnd[v]=GRAY;
                d[v]=++T;
                st.push(v);
            }
        }else{
            st.pop();
            cnd[u]=BLACK;
            f[u]=++T;
        }
    }
}

void outp(){
    for(int i=0;i<n;i++){
        cnd[i]=WHITE;
        //nt[i]=0;
    }

    for(int j=0;j<n;j++){
        if(cnd[j]==WHITE)visit(j);
    }
    for(int k=0;k<n;k++){
        cout<<k+1<<" "<<d[k]<<" "<<f[k]<<endl;
    }
}

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

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

int t=0,k,n;
int gone[100+10]={},before[100+10]={},a[100+10][100+10]={};

void dfs(int cur){
    if(gone[cur]!=1){
        t+=1;
        cerr << "visiting " << cur << " at " << t << endl;
        gone[cur]=1;
    }
    for(int m=1;m<=n;m++){
        if(a[cur][m]==1){
            if(gone[m]==0){
                dfs(m);
            }
        }
    }
    t+=1;
    cerr << "complete " << cur << " at " << t << endl;
}

int main(){
    cin >> n;
    for(int i=1;i<=n;i++){
        int u,p;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            cin >> p;
            a[i][p]=1;
        }
    }
    for(int q=1;q<=n;q++){
        if(gone[q]!=1) dfs(q);
    }
}

C++: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

vector<vector<int>> G(101, vector<int>(0));
vector<int> c(101, 0);
vector<int> d(101, 0);
vector<int> f(101, 0);

template <class T> void vecout(T V) {
    auto t = V.begin();
    *t++;
    while(t != V.end()) {
        cout << " " << *t++;
        // if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int t = 0;
void dfs(int i) {
    if(c[i]) return;
    c[i] = 1;
    d[i] = ++t;
    for(auto e : G[i])
        dfs(e);
    f[i] = ++t;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b, c;
    cin >> n;
    rep(i, n) {
        cin >> a >> b;
        rep(j, b) {
            cin >> c;
            G[a].push_back(c);
        }
    }
    rep(i, 1, n + 1) dfs(i);

    rep(i, 1, n + 1) cout << i << " " << d[i] << " " << f[i] << "\n";
}

C++: 	#include<stdio.h>
	int k[101]={0},d[101]={},f[101]={};
	int v[101][101]={0};
	int cur;
	void dfs(int id){
		if(d[id]!=0){
			return;
			}
			cur++;
			if(d[id]==0){
				d[id]=cur;
			}
			for(int i=0;i<k[id];i++){
				dfs(v[id][i]);
			}
			cur++;
			f[id]=cur;
			return;
		}
		int main(void){
		int n=0,u=0;
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d",&u);
			scanf("%d",&k[u]);
			for(int j=0;j<k[u];j++){
				scanf("%d",&v[u][j]);//uからいけるj個目のノードがv[u][j]
			}
		}
		for(int i=1;i<n;i++){
		if(d[i]==0){
		dfs(i);
		}
		}
		for(int i=1;i<=n;i++){
			printf("%d %d %d\n",i,d[i],f[i]);
		}
	return(0);
}