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 fp 				pop_front
#define bp 				pop_back
#define all(x) 			x.begin() , x.end()
#define mp 				make_pair
#define pb 				push_back
#define pf 				push_front
#define se 				second
#define f 				first
#define sz 				size()
#define sqr(x) 			((x) * (x))
#define cub(x) 			sqr(x) * (x)
#define ios 			std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
#define y1 				qazwsxedcrfvtgb
#define LOGMAX          17
#define MX              1 << 22
#define l(n)            n << 1
#define r(n)            (n << 1) + 1
#define FIND(N,pos)     ((N) & (1 << (pos)))
#define sf(h)           scanf("%d",&h)
#define sff(h,b)        scanf("%d%d",&h,&b)
#define sfff(h,b,c)     scanf("%d%d%d",&h,&b,&c)
#define TCASE(test)     for(int z = 1;z <= test;z++)
#define PRINT           printf("Case %d: ",z)
#define en              "\n"
#define lwb             lower_bound
#define upb             upper_bound
#define	pii				pair <int, int>
#define	pil				pair <int, long long>
#define	pli				pair <long long, int>
#define	pll				pair <long long, long long>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int maxn = int(1.5 * 1e7);
const int inf = 1e9 + 7;
const ll ll_inf = 1e18 + 420;
const double eps = 1e-4;
const int N = 1e6 + 7;
const int MAX = 2e5 + 9;

int n, x, y, k1, t, a[101][101], st[101], ft[101], was[101];
vector <int> v[101];

void dfs(int k){
	st[k] = ++t;
	was[k] = 1;
	for(int i = 0; i < v[k].sz; ++i){
		int to = v[k][i];
		if(!was[to]){
			dfs(to);
		}
	}
	ft[k] = ++t;
}

main(){
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> x >> k1;
		for(int j = 0; j < k1; ++j){
			cin >> y;
			v[x].pb(y);
		}
	}
	dfs(1);
	for(int i = 1; i <= n; ++i){
		cout << i << " " << st[i] << " " << ft[i] << en;
	}
}

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

#define MAX 100

enum SATE {
    NOT_VISIT,
    DISCOVER,
    FOUND
};

int G[MAX+1][MAX+1], d[MAX+1], f[MAX+1], STATE[MAX+1];
int n, tt;
std::stack<int> S;

void dfs(int i) {
    S.push(i);
    STATE[i] = DISCOVER;
    d[i] = ++tt;

    for (int j = 1; j <= n; ++j) {
        if (G[i][j] != 1 || STATE[j] != NOT_VISIT) continue;
        dfs(j);
    }
    STATE[i] = FOUND;
    f[i] = ++tt;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        d[i] = f[i] = 0;
        STATE[i] = NOT_VISIT;
        for (int j = 1; j <= n; ++j) {
            G[i][j] = 0;
        }
    }
    for (int i = 0; i < n; ++i) {
        int u,k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; ++j) {
            int t;
            scanf("%d", &t);
            G[u][t] = 1;
        }
    }

    tt = 0;
    for (int i = 1; i <= n; ++i) {
        if (STATE[i] == NOT_VISIT) dfs(i);
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

int find_t[101],end_t[101];
int lft[101],rht[101];
int flag[101];
int t=1;

void DFS(int);
void Print();

int main(int argc,char* argv[]){
  int n,id,cnt,x;
  
  memset(find_t,255,sizeof(find_t));
  memset(end_t,0,sizeof(end_t));
  memset(lft,255,sizeof(lft));
  memset(rht,255,sizeof(rht));
  memset(flag,0,sizeof(flag));

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>id>>cnt;
    flag[id]=0;
    for(int l=0;l<cnt;l++){
      cin>>x;
      (l==0) ? lft[id]=x : rht[id]=x;
    }
  }
  
  for(int i=1;i<=n;i++){
    if(flag[i]==0)
      DFS(i);
  }
  Print();
  
  return 0;
}

  void DFS(int p){
    if(flag[p]==0){
      find_t[p]=t++;
      flag[p]=1;
    }
    else
      return;
    
    if(lft[p]!=-1)
      DFS(lft[p]);
    if(rht[p]!=-1)
      DFS(rht[p]);

    end_t[p]=t++;
  }

  void Print(){
    for(int i=1;i<=100;i++){
      if(find_t[i]!=-1)
	printf("%d %d %d\n",i,find_t[i],end_t[i]);
    }
  }

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

const int WHITE=0, GRAY=1, BLACK=2;

struct DFS {
    int n;
    vector<vector<int>> g;
    vector<int> discover;
    vector<int> finish;
    vector<int> state;
    int time = 1;
    
    DFS(int n):n(n) {
        g.assign(n, vector<int>());
        discover.assign(n, -1);
        finish.assign(n, -1);
        state.assign(n, WHITE);
    }
    
    void addEdge(int u, int v) {
        g[u].push_back(v);
    }
    
    void solve() {
        for (int i = 0; i < n; i++) {
            if (state[i] == WHITE) {
                dfs(i);
            }
        }
    }
    
    void dfs(int u) {
        state[u] = GRAY;
        discover[u] = time++;
        for (int v : g[u]) {
            if (state[v] == WHITE) {
                dfs(v);
            } 
        }
        finish[u] = time++;
        state[u] = BLACK;
    }
    
    void print() {
        for (int i = 0; i < n; i++) {
            cout << i << ":";
            for (int v : g[i]) {
                cout << v << " ";
            }
            cout << endl;
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    DFS dfs(n);
    for (int i = 0; i < n; i++) {
       int u, k;
       cin >> u >> k;
       u--;
       for (int j = 0; j < k; j++) {
           int v;
           cin >> v;
           v--;
           dfs.addEdge(u, v);
       }
    }
    
    //dfs.print();
    
    dfs.solve();
    
    for (int i = 0; i < n; i++) {
        cout << (i + 1) <<  " " << dfs.discover[i] << " " << dfs.finish[i] << endl; 
    }
    
    return 0;
}