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"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

vector<int> D,F;

int dfs(int t,int p,int c,ConnectNodeInfo& connect){
	D[c]=t;
	for(auto& x:connect[c]){
		if(x.first!=p && D[x.first]==0){
			t = dfs(t+1,c,x.first,connect);
		}
	}
	t++;
	F[c]=t;
	return t;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	ConnectNodeInfo connect(N);
	vector<int> V(N);
	REP(i,N){
		int x=in()-1,k=in();
		REP(j,k){
			int y=in()-1;
			connect.AddDirectionalConnection(x,y,1);
		}
		V[i]=x+1;
	}
	D.resize(N,0);
	F.resize(N,0);
	int T=1;
	REP(i,N){
		if(D[i]==0) T = dfs(T,-1,i,connect)+1;
	}

	REP(i,N){
		out(V[i],D[i],F[i]);
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int N;
int tt = 0;
vector< vector<int> > G;
vector<int> H, d, f;
int itrNum[100001];
stack<int> S;

void dfs(int u){
    S.push(u);
    H[u] = 0;

    while(!S.empty()){
        u = S.top();  // ?¨????????????????
        if(d[u] == 0) d[u] = ++tt;
        auto itr_v = next(G[u].begin(), itrNum[u]);
        itrNum[u]++;
        if(itr_v != G[u].end()){
            int v = *itr_v;
            if(H[v] == -1){
                H[v] = 0;
                S.push(v);
            }
        }else{
            S.pop();
            H[u] = 1;
            f[u] = ++tt;
        }
    }
}

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

    cin >> N;
    G = vector<vector<int> >(N);
    H = vector<int>(N, -1);
    d = vector<int>(N, 0);
    f = vector<int>(N, 0);
    memset(itrNum, 0, sizeof(itrNum));
    REP(i, N){
        int u,k;
        cin >> u >> k;
        u--;
        REP(j ,k){
            int v;
            cin >> v;
            v--;
            G[u].pb(v);
        }
    }

    REP(i, N) if(H[i] == -1) dfs(0);
    REP(i, N){
        cout << i+1 << " " << d[i] << " " << f[i] << "\n";
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int a[101][101],f[101],e[101],t=1;
int color[101];
int n;

void dfs(int u){
    f[u]=t++;
    color[u]=1;
    rep(v,n){
        if(color[v]==0 && a[u][v]) dfs(v);
    }
    e[u]=t++;

}

int main() {
    cin>>n;
    rep(i,n){
        int u,cur;
        cin>>u>>cur;
        rep(j,cur){
            int v;
            cin>>v;
            a[u-1][v-1]=1;
        }
    }
    rep(i,n){
        if(!color[i]) dfs(i);
    }
    rep(i,n) cout<<i+1<<" "<<f[i]<<" "<<e[i]<<endl;
}