Go: package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

C++: #include <algorithm>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>

using namespace std;

map<int, vector<int>> V;
map<int, int> pre;
map<int, int> post;
int t = 1;

int _DFS(int v, vector<bool> &visited) {
  pre[v] = t;
  ++t;
  for (int out_nbr_id : V[v]) {
    if (!visited[out_nbr_id]) {
      visited[out_nbr_id] = true;
      _DFS(out_nbr_id, visited);
    }
  }
  post[v] = t;
  ++t;
}

int main() {
  int n;
  cin >> n;

  vector<bool> visited(n, false);

  cin.ignore();

  for (string line; getline(cin, line);) {
    istringstream is{line};
    int id, n_nbrs, nbr;
    is >> id >> n_nbrs;
    vector<int> out_nbrs;
    while (is >> nbr)
      out_nbrs.push_back(nbr);
    V[id] = out_nbrs;
  }

  for (auto vadj : V) {
    if (!visited[vadj.first]) {
      visited[vadj.first] = true;
      _DFS(vadj.first, visited);
    }
  }

  for (auto vadj : V) {
    int id = vadj.first;
    cout << id << " " << pre[id] << " " << post[id] << endl;
  }
}

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

using namespace std;

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

struct DFS {
    int n;
    vector<vector<int>> g;
    vector<int> color;
    vector<int> dt;
    vector<int> ft;
    int ct = 1;
 
    DFS(int n) : n(n) {
        g.assign(n, vector<int>());
        color.assign(n, WHITE);
        dt.assign(n, -1);
        ft.assign(n, -1);
    }
    
    void solve() {
        for (int i = 0; i < n; i++) {
            if (color[i] == WHITE) {
                dfs(i);
            }
        }
    }
    
    void dfs(int u) {
        //cout << "visit " << u << endl;
        color[u] = GREY;
        dt[u] = ct++; 
        for (int v : g[u]) {
            if (color[v] == WHITE) {
                dfs(v);
            }
        }
        ft[u] = ct++;
        color[u] = BLACK;
    }
    
    void addEdge(int u, int v) {
        g[u].push_back(v);
    }
    
    void printGraph() {
        for (int i = 0; i < n; i++) {
            cout << i << ": ";
            for (int v : g[i]) {
                cout << v << " ";
            }
            cout << endl;
        }
    }
        
};


int main() {   
    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.printGraph();
    
    dfs.solve();
    
    for (int i = 0; i < n; i++) {
        cout << (i + 1) << " " << dfs.dt[i] << " " << dfs.ft[i] << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <cstring>
#define N 101

using namespace std;

int visited[N], discovery[N], finish[N], tt, n;
vector<int> G[N];

void dfs(int u) {
    visited[u] = 1;
    discovery[u] = ++tt;
    for (int i = 0; i < G[u].size(); i++) {
        if (visited[G[u][i]] == 0) {
            dfs(G[u][i]);
        }
    }
    finish[u] = ++tt;
}

int main() {
    int u, k, v;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            G[u].push_back(v);
        }
    }
    memset(visited, 0, sizeof(visited));
    tt = 0;

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

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

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;

class Graph{
public:
  int v;
  int ftime = -1;
  int ltime = -1;
  vector<int> e;
};
vector<Graph> g;
int cnt = 0;
void dfs(int pos){
  if( g[pos].ftime != -1 ) return;
  cnt++;
  g[pos].ftime = cnt;
  for(int i=0; i<g[pos].e.size(); i++){
    dfs(g[pos].e[i]);
  }
  cnt++;
  g[pos].ltime = cnt;
}

int main(void) {

  int n;
  cin >> n;
  g.resize(n);
  int u, k;
  for(int i=0; i<n; i++){
    cin >> u >> k;
    u--;
    g[u].v = u;
    g[u].e.resize(k);
    for(int j=0; j<k; j++){
      cin >> g[u].e[j];
      g[u].e[j]--;
    }
    sort(g[u].e.begin(), g[u].e.end());
  }
  for(int i=0; i<n; i++) dfs(i);
  for(int i=0; i<n; i++){
    cout << g[i].v + 1 << " " << g[i].ftime << " " << g[i].ltime << endl;
  }



  return 0;
}

// EOF

C++: #include <iostream>
#include <vector>

using namespace std;

int tim = 0;
vector<vector<int>> to;
vector<bool> reached;
vector<int> d;
vector<int> f;



void dfs(int point);

int main()
{
    int n;
    cin >> n;
    to.resize(n+1);
    for(int i = 1; i <= n; i++){
        int m;
        cin >> m;
        cin >> m;
        to[i].resize(m);
        for(int j = 0; j < m; j++){
            cin >> to[i][j];
        }
    }
    
    reached.resize(n+1);
    d.resize(n+1);
    f.resize(n+1);

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

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

    return 0;
}

void dfs(int point)
{
    tim++;
    reached[point] = true;
    d[point] = tim;

    for(int i = 0; i < to[point].size(); i++){
        if(!reached[to[point][i]]){
            dfs(to[point][i]);
        }
    }
    tim++;
    f[point] = tim;    

}