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 rep(i,n) for(int i = 0; i < (n) ; i++)
constexpr auto INF = 2147483647;
typedef long long ll;

int main(){

  int vertex_num, time;
  cin >> vertex_num;
  vector<vector<int>> adjacent_graph;
  adjacent_graph.resize(101);
  int discover[101],finished[101];
  rep(i,101) discover[i] = finished[i] = -1;

  rep(i,vertex_num){
    int vertex, adjacent_num,tmp;
    vector<int> input_graph;
    cin >> vertex >> adjacent_num;
    rep(j,adjacent_num){
      cin >> tmp;
      input_graph.emplace_back(tmp);
    }
    adjacent_graph[vertex] = input_graph;
  }

  stack<int> stk;
  time = 0;
  for(int i=1;i<=vertex_num;i++){
    if(discover[i] == -1){
      stk.emplace(i);
      discover[i] = ++time;
    }
    while(!stk.empty()){
      int now = stk.top();
        bool hasnext = false;
        rep(j,adjacent_graph[now].size()){
          int next = adjacent_graph[now][j];
          if(discover[next] == -1) {
            discover[next] = ++time;
            stk.emplace(next);
            hasnext = true;
            break;
          }
        }
        if(!hasnext){   
        finished[now] = ++time;
        stk.pop();
        }
    }
  }

  for(int i =1;i<=vertex_num; i++){
    cout << i << " " << discover[i] << " " << finished[i] << endl;
  }

  return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

struct Node{
    int id, v;
    bool done = false;
    Node(int id, int v=0): id(id), v(v) {}
    Node(): id(0), v(0) {}

    bool operator==(const Node& x) { return v == x.v; }
    bool operator!=(const Node& x) { return v != x.v; }
    bool operator<(const Node& x) { return v < x.v; }
    bool operator>(const Node& x) { return v > x.v; }
    bool operator<=(const Node& x) { return v <= x.v; }
    bool operator>=(const Node& x) { return v >= x.v; }

    bool comp(Node node){
        return v < node.v;
    }
};

struct Edge{
    int from, to, cost, id;
    Edge(int from, int to, int cost=1, int id=-1): from(from), to(to), cost(cost), id(id) {}

    bool comp(Edge e){
        return cost < e.cost;
    }
};

struct Graph{
    int N;
    vector<vector<Edge>> adj;
    vector<Node> node;

    Graph(int N): N(N) {
        adj.resize(N, vector<Edge>());
        node.resize(N);
        for(int i=0; i<N; ++i) node[i].id = i;
    }

    Graph() {}

    void add_edge(int i, int j, int cost=1, int id=-1){
        Edge e(i, j, cost, id);
        adj[i].emplace_back(e);
    }

    vector<Edge> get_adj(Node node){
        return adj[node.id];
    }

    void assign(int n){
        N = n;
        adj.assign(N, vector<Edge>());
        node.assign(N, Node());
        for(int i=0; i<N; ++i) node[i].id = i;
    }
};

Graph G;
VI d,f;

int dfs(int node, int t){
    G.node[node].done = true;
    d[node] = t;

    for(Edge e : G.adj[node]){
        if(G.node[e.to].done) continue;
        t = dfs(e.to, t+1);
    }

    f[node] = t+1;
    return t+1;
}

int main(void){
    int n; cin >> n;
    d.assign(n,0);
    f.assign(n,0);
    G.assign(n);
    REP(i,n){
        int u,k; cin >> u >> k;
        u--;
        REP(j,k){
            int v; cin >> v;
            v--;
            G.add_edge(u,v);
        }
    }

    int t = 0;
    REP(i,n){
        if(G.node[i].done) continue;
        t = dfs(i,t+1);
    }

    REP(i,n) cout << i+1 << " " << d[i] << " " << f[i] << en;
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>



using namespace std;




int main() {
	
	int n;
	cin>>n;
	vector<vector<int>>t(n,vector<int>(n));
	for(int i=0;i<n;i++){
		int x,r;cin>>r>>x;
		for(int j=0;j<x;j++){
			int w;cin>>w;w--;t[i].push_back(w);
			t[w].push_back(i);
		}
		sort(t[i].begin(),t[i].end());
	}
	for(int i=0;i<n;i++){
		sort(t[i].begin(),t[i].end());
	}
	stack<int>S;
	bool F[105]={};
	S.push(0);
	int p=1;
	F[0]=1;
	vector<int>G(n),H(n);
	int g=1;
	G[0]=1;
	while(S.size()){
		g++;
		int v=S.top();
		int a=-1;
		for(int i=0;i<t[v].size();i++){
			if(!F[t[v][i]]){
				a=t[v][i];break;
			}
		}
		if(a==-1){
			H[S.top()]=g;
			S.pop();
		}
		else{
			F[a]=1;
			G[a]=g;
			S.push(a);
		}
	}
	for(int i=0;i<n;i++){
		cout<<i+1<<" "<<G[i]<<" "<<H[i]<<endl;
	}
	

	
	return 0;
}