Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include<bits/stdc++.h>
using namespace std;
int a[105][105];
pair<int,int> ans[105];
int co;
int n;
void dfs(int x){
  if(ans[x].first==0){
    co++;
    ans[x].first = co ;
  }
  //cout << n << endl;
  for(int i=0;i<n;i++){
    //cout << a[x][i]<<endl;
    if(a[x][i]==1)dfs(i);
  }
  if(ans[x].second==0){
    co++;
    ans[x].second=co;
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    int u,m;
    cin >> u >> m;
    for(int j=0;j<m;j++){
      int v;
      cin >> v;
      a[u-1][v-1]=1;
    }
  }
  dfs(0);
  for(int i=0;i<n;i++){
    cout << i+1 << " " << ans[i].first << " "<< ans[i].second << endl;
  }
  return 0;
}

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

const int MAXINT = std::numeric_limits<int>::max();

// typedef std::vector<std::vector<int> > mat_int;
// typedef std::vector<std::vector<bool> > mat_bool;

void dfs(std::vector<std::vector<int> >& adj_list, std::vector<int>& d, std::vector<int>& f, int& time, int root = 0 ){
  if(d[root] > time){
    d[root] = time;
    for(int const& v: adj_list[root]){
      time++;
      dfs(adj_list, d, f, time, v);
    }
    time++;
    f[root] = time;
  }

}


int main(int argc, char const *argv[]) {
  int n; // .. 100
  std::cin >> n;
  // mat_bool adj(n, std::vector<bool>(n));
  // mat_int d(n, std::vector<int>(n)), f(n, std::vector<int>(n));
  std::vector<std::vector<int> > adj_list(n);
  std::vector<int> d(n, MAXINT), f(n, MAXINT);

  for(int q=0; q<n; ++q){
    int i_plus_1, k;
    std::cin >> i_plus_1;
    std::cin >> k;
    for(int p=0; p<k; ++p){
      int j_plus_1;
      std::cin >> j_plus_1;
      // adj[i_plus_1-1][j_plus_1-1] = true;
      adj_list[i_plus_1 - 1].push_back(j_plus_1-1);
    }
  }

  int t = 1;
  dfs(adj_list, d, f, t);

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

  }


  // for(auto it = adj_list.begin(); it != adj_list.end(); ++it){
  //   std::cout << ": ";
  //   for(auto jt = (*it).begin(); jt != (*it).end(); ++jt){
  //     std::cout << (*jt) << ' ';
  //   }
  //   std::cout << std::endl;
  // }

  return 0;
}

C++: #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define debug(x) cout<< #x <<": "<<x<<endl
#define debug2(x,y) cout<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector< T > >;

vi ts_d;
vi ts_f;

template<class T>
void dfs(int cur, int &time_visit, T graph) {
  // visiting cur
  time_visit += 1;
  ts_d[cur] = time_visit;
  for (auto dst : graph[cur]) {
    if (ts_d[dst] == 0) {
      dfs(dst, time_visit, graph);
    }
  }
  time_visit += 1;
  ts_f[cur] = time_visit;
}

int main() {
  int time = 0;
  int n;
  cin >> n;
  ts_d.reserve(n);
  ts_f.reserve(n);
  ts_d.assign(1, 0);
  vector<set<int> > graph(n, set<int>());

  for (int i = 0; i < n; ++i) {
    int num;
    cin >> num;
    num -= 1;
    int out;
    cin >> out;
    for (int j = 0; j < out; ++j) {
      int tmp;
      cin >> tmp;
      tmp -= 1;
      graph[i].insert(tmp);
    }
  }

  dfs(0, time, graph);

  for (int i = 0; i < n; ++i) {
    printf("%d %d %d\n", i+1, ts_d[i], ts_f[i]);
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
vector<vector<int>> a;
vector<int> b;
vector<int> s;
vector<int> t;
int c = 1;

void dfs(int x)
{
  if (b[x]==1) return;
  b[x] = 1;
  s[x] = c; c++;
  for (auto v:a[x]) {
    dfs(v);
  }
  t[x] = c; c++;
}

int main()
{
  int n; cin>>n;
  a.resize(n);
  b.resize(n); rep(i, n) b[i]=0;
  s.resize(n); rep(i, n) s[i]=0;
  t.resize(n); rep(i, n) t[i]=0;
  rep(i, n) {
    int u; cin>>u; u--;
    int k; cin>>k;
    rep(j, k) {
      int v; cin>>v; v--;
      a[u].push_back(v);
    }
  }
  rep(i, n) dfs(i);
  rep(i, n) printf("%d %d %d\n", i+1, s[i], t[i]);

  return 0;
}

C++: //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

vector<vector<int>> a(0);
int g;
vector<int> s(0),t(0);
int cnt=1;

int dfs(int x){
    s[x]=cnt;
    cnt ++;
    for(auto y:a[x]){
        if(s[y]==-1){
            dfs(y);
        }
    }
    t[x]=cnt;
    cnt ++;
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    cin>>g;
    a=vector<vector<int>>(g,vector<int>(0));
    int k,x;
    rep(i,g){
        cin>>k;
        cin>>k;
        rep(j,k){
            cin>>x;
            a[i].emplace_back(x-1);
        }
    }
    s.resize(g,-1);t.resize(g,-1);
    rep(i,g){
        if(s[i]==-1) dfs(i);
    }
    rep(i,g) cout<<i+1<<" "<<s[i]<<" "<<t[i]<<'\n';
}

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

struct ver{
    ll d;
    ll f;
};

ll t=0;
vector<vector<ll>> mat;
vector<ver> vers;

void find(ll pos) {
    t++;
    if(vers[pos].d == 0){
        vers[pos].d = t;
    }
    for(ll i:mat[pos]) {
        find(i);
    }
    t++;
    if(vers[pos].f == 0) {
        vers[pos].f = t;
    }
}

int main() {
    ll n;
    cin >> n;
    for(ll i=0;i<n;i++) {
        ll u,k;
        cin>>u>>k;
        vector<ll> aaa;
        for(ll j=0;j<k;j++) {
            ll tmp;
            cin>>tmp;
            aaa.push_back(tmp-1);
        }
        mat.push_back(aaa);
    }
    for(ll i=0;i<n;i++) {
        vers.push_back(ver{0,0});
    }
    find(0);
    for(ll i=0;i<n;i++) {
        cout << i+1<<" "<<vers[i].d<<" "<<vers[i].f<<endl;
    }
}