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 <iostream>
#include <stack>
using namespace std;
static const int N=100;
static const int WHITE=1;
static const int GRAY=2;
static const int BLACK=3;

int n,M[N][N];
int color[N],d[N],f[N],nt[N],tt;

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++) ;
    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;
        }
    }

}

void dfs()
{
    for(int i=0;i<n;i++)
    {
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;

    for(int u=0;u<n;u++)
    {
        if(color[u]==WHITE) dfs_visit(u);
    }

    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;
}

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

void dfs(vector<vector<int> > &G, vector<bool> &seen, vector<int> &d, vector<int> &f, int v, int &t) {
    seen[v] = true;
    d[v] = ++t;
    for (int i = 0; i < G[v].size(); i++) {
        if (seen[G[v][i]]) continue;
        dfs(G, seen, d, f, G[v][i], t);
    }
    f[v] = ++t;
}

void print(int n, vector<int> &d, vector<int> &f) {
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<int> > G(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--;
            G[u].push_back(v);
        }
    }

    vector<bool> seen(n, false);
    vector<int> d(n), f(n);
    int t = 0;
    for (int i = 0; i < n; i++) {
        if (seen[i]) continue;
        dfs(G, seen, d, f, i, t);
    }
    print(n, d, f);

    return 0;
}

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

const int MAX_N = 110;
int G[MAX_N][MAX_N];
int D[MAX_N], F[MAX_N], V[MAX_N];

void dfs(int u, int n, int& count) {
  int i;
  V[u] = 1;
  D[u] = ++count;
  for (i = 0; i < n; ++i) {
    if (G[u][i] && !V[i]) {
      dfs(i, n, count);
    }
  }
  F[u] = ++count;
}

int main() {
  int i, j, u, k, v, n, count;
  
  cin >> n;

  for (i = 0; i < n; ++i) {
    cin >> u >> k;
    for (j = 0; j < k; ++j) {
      cin >> v;
      G[u - 1][v - 1] = 1;
    }
  }

  count = 0;
  for (i = 0; i < n; ++i) {
    if (!V[i]) dfs(i,n,count);
  }

  for (i = 0; i < n; ++i) {
    cout << i + 1 << ' ' << D[i] << ' ' << F[i] << '\n';
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define MAX 105
#define INF (1<<30)
//#define EZPZ_LEMON_SQUEENZ
using namespace std;

vector<int> M[MAX];
stack<int> s;
int states[MAX][2];
bool vis[MAX];
int n, t;

void dfs(int index)
{
	if (index == n + 1) return;
	vis[index] = true;
	for (int i = 0; i < M[index].size(); i++)
	{
		if (!vis[M[index][i]]) {
			states[M[index][i]][0] = t++;
			dfs(M[index][i]);
			states[M[index][i]][1] = t++;
		}
	}
}

int main()
{
#ifdef EZPZ_LEMON_SQUEENZ
	freopen("D:\\in.txt", "r", stdin);
	freopen("D:\\out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int b, nn, e;
		cin >> b >> nn;
		for (int j = 1; j <= nn; j++) {
			cin >> e;
			M[b].push_back(e);
		}
	}
	t = 1;
	for (int i = 1; i <= n; i++)
	{
		if (!vis[i]) {
			states[i][0] = t++;
			dfs(i);
			states[i][1] = t++;
		}
	}
	for (int i = 1; i <= n; i++) cout << i << " " << states[i][0] << " " << states[i][1] << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

const int mxN = 102;
vector<int> adj[mxN], in(mxN, -1), out(mxN, -1);
int t = 0;

void dfs(int i) {
    t++;
    in[i] = t;
    for(auto v: adj[i]) {
        if(in[v]==-1) {
            dfs(v);
        }
    }
    t++;
    out[i] = t;
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int v, k;
        cin >> v >> k;
        for(int j = 0; j < k; j++) {
            int a;
            cin >> a;
            a--;
            adj[i].push_back(a);
        }
    }
    for(int i = 0; i < n; i++) {
        if(in[i] == -1) dfs(i);
    }
    for(int i = 0; i < n; i++) {
        cout << i+1 << " " << in[i] << " " << out[i] << endl;
    }
}