Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	dfs(&g, &d, &f, 1, 1)

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

vector<int> g[101];
bool visited[101]{};
P ans[101];

int dfs(int s, int t) {
    visited[s] = true;
    ans[s].first = t;
    REP(i, g[s].size()) {
        if (visited[g[s][i]]) continue;
        t = dfs(g[s][i], t + 1);
    }
    t++;
    ans[s].second = t;
    return t;
}

int main() {
    int n;
    cin >> n;
    REP(i, n) {
        int u, m;
        cin >> u >> m;
        REP(j, m) {
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    for (int i = 1, T = 0; i <= n; i++) {
        if (visited[i]) continue;
        T = dfs(i, T+1);
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}

C++: // ALDS1_12_A: Depth First Search
#include <iostream>
#include <vector>
#include <algorithm>
bool debug = false;

std::vector<std::pair<int,int>> runtime_memo;
std::vector<int> vertex_stat;
std::vector<std::vector<int>> adjacency_list;
int runtime = 0;

void init() {
    int total; std::cin >> total;
    /* Resize containers */
    runtime_memo.resize(total);
    vertex_stat.resize(total);
    adjacency_list.resize(total);
    for (int i=0;i<adjacency_list.size(); i++) {
        adjacency_list.at(i).resize(total);
    }
    for (int i=0; i<adjacency_list.size(); i++) {
        for (int j=0; j<adjacency_list.at(i).size(); j++) {
            adjacency_list.at(i).at(j) = 0;
        }
    }

    /* Set adjacency_list */
    int vertex, outdegree;
    for (int i=0; i<adjacency_list.size(); i++) {
        std::cin >> vertex >> outdegree;
        for (int j=0; j<outdegree; j++) {
            int tmp; std::cin >> tmp;
            adjacency_list.at(vertex-1).at(tmp-1) = 1;
        }
    }
}

void DepthFirstSearch(int vertex) {
    int tmp_vertex = vertex -1;
    vertex_stat.at(tmp_vertex) = 1;
    runtime++;
    runtime_memo.at(tmp_vertex).first = runtime;
    for (int i=0; i<adjacency_list.at(tmp_vertex).size(); i++) {
        if (adjacency_list.at(tmp_vertex).at(i) == 1) {
            if (vertex_stat.at(i) == 0) {
                if (debug) std::cout << "DepthFirstSearch(" << i+1 << ")" << "\n";
                DepthFirstSearch(i+1);
            }
        }
    }
    vertex_stat.at(tmp_vertex) = 2;
    runtime++;
    runtime_memo.at(tmp_vertex).second = runtime;
}

int main() {
    /* Initialization */
    init();
    /* Depth first search */
    for (int i=0; i<vertex_stat.size(); i++) {
        int id = i+1;
        if (vertex_stat.at(i) == 0) {
            DepthFirstSearch(id);
        }
    }
    /* Output */
    for (int i=0; i<adjacency_list.size(); i++) {
        int id = i+1;
        std::cout << id << " ";
        std::cout << runtime_memo.at(i).first << " ";
        std::cout << runtime_memo.at(i).second << "\n";
    }
}

C++: #include <iostream>
#include <cstdio>
#include <stack>

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

using namespace std;


int adjacencyList[MAX + 1][MAX + 1];
int color[MAX + 1];
int d[MAX + 1];
int f[MAX + 1];
int n;
int timer;



int minWhiteNode(int v)
{

	for (int i = 1; i <= n; i++) {
		if (color[i] == WHITE && adjacencyList[v][i] == 1) {
			return i;
		}
	}
	return 	MAX + 1;
}


void dfs(int o)
{
	stack<int> S;
	int cr;


	S.push(o);
	color[o] = GRAY;
	d[o] = ++timer;

	while (S.size() > 0) 
	{
		cr = minWhiteNode(S.top());
		timer++;

		if (cr != MAX + 1) {
			S.push(cr);
			color[cr] = GRAY;
			d[cr] = timer;
		}
		else {
			int poped = S.top();
			S.pop();
			color[poped] = BLACK;
			f[poped] = timer;
		}
	}
}

int main(void)
{

	int u;
	int k;
	int v;


	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> u >> k;

		for (int j = 0; j < k; j++) {
			cin >> v;
			adjacencyList[u][v] = 1;
		}

	}

	for (int i = 1; i <= n; i++) {
		if (color[i] == WHITE) {
			dfs(i);
		}
	}

	for (int i = 1; i <= n; i++) {
		cout << i << " " <<d[i] << " " << f[i] << endl;
	}

	return 0;
}

C++: #include<stdio.h>
int T=1,m[101][101],d[101]={0},a[101],b[101],n;
void visit(int u){
  int v; 
  a[u]=T++;
  d[u]=1;
  for(v=0;v<n;v++){
    if(m[u][v]==1&&d[v]==0){ 
      visit(v);
    }
  }   
  b[u]=T++;  
}
#include<stdio.h>
int main(){
  int k,i,j,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      m[i][j]=0;
 for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
       m[u-1][v-1]=1;      
   }
 }
 visit(0);
 for(i=0;i<n;i++)
   printf("%d %d %d\n",i+1,a[i],b[i]);
 return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack<int> st;
int  v[102][101], n;
int  tim[102][2];
int ct = 1;
inline void search(int t) {
	if(!tim[t][0]) tim[t][0] = ct++;
	int tf = 0;
	for (int a = 1; a <= n; a++) {
		if (v[t][a]) {
			st.push(a);
			for (int i = 1; i <= n; i++) {
				v[i][a] = 0;
			}
			search(st.top());
			tf = 1;
		}
	}
		
	if(!tf) {
		st.pop();
		tim[t][1] = ct++;
		if(!st.empty()) search(st.top());
	}
}
int main() {
	st.push(1);
	int u, k, s;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			v[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			v[u][s] = 1;
		}
	}
	search(1);
	for (int i = 1; i <= n; i++) {
		cout << i << " " << tim[i][0] << " " << tim[i][1] << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

const int N = 100;
int A[N][N] = {{0}};
int n;
int t = 0;
int d[N] = {0};
int f[N] = {0};

void dfs(int id) {
    // cerr << "begin: " <<  id << " " << t << endl;
    if (d[id] != 0) {
        return;
    }
    ++t;
    d[id] = t;

    for (int i = 0; i < n; ++i) {
        if (A[id][i] != 0) {
            dfs(i);
        }
    }

    // cerr << "end: " <<  id << " " << t << endl;
    if (f[id] == 0) {
        ++t;
        f[id] = t;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u;
        cin >> u;

        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int x;
            cin >> x;
            A[u-1][x-1] = 1;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (d[i] == 0)
            dfs(i);
    }


    for (int i = 0; i < n; ++i) {
        cout << i + 1 << " ";
        cout << d[i] << " " << f[i];
        cout << endl;
    }

    return 0;
}