Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

type graph struct {
	size  int
	edges [][]int
}

func parseProblem() *graph {
	n := scanInt(sc)
	g := &graph{
		size:  n,
		edges: make([][]int, n),
	}
	for i := 0; i < g.size; i++ {
		_ = scanInt(sc)
		k := scanInt(sc)
		g.edges[i] = make([]int, k)
		for j := 0; j < k; j++ {
			g.edges[i][j] = scanInt(sc) - 1
		}
	}
	return g
}

func resolve(g *graph) {
	ds := make([]int, g.size)
	fs := make([]int, g.size)
	time := 0
	for i := 0; i < len(ds); i++ {
		if ds[i] == 0 {
			time++
			time = _dfs(ds, fs, time, g, i)
		}
	}
	for i := 0; i < len(ds); i++ {
		fmt.Println(i+1, ds[i], fs[i])
	}
	return
}

func _dfs(ds, fs []int, time int, g *graph, idx int) int {
	ds[idx] = time
	for _, next := range g.edges[idx] {
		if ds[next] > 0 {
			continue
		}
		time++
		time = _dfs(ds, fs, time, g, next)
	}
	time++
	fs[idx] = time
	return time
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

int n;
int t;
vector<int> G[MAX];
bool used[MAX];
int d[MAX];
int f[MAX];

void DFS(int s) {
	if (used[s]) return;
	used[s] = true;
	d[s] = t++;
	for (int &v : G[s]) {
		DFS(v);
	}
	f[s] = t++;
}

int main()
{
	cin >> n;
	for (int i = 0, u, k; i < n; i++) {
		cin >> u >> k;
		for (int j = 0, v; j < k; j++) {
			cin >> v;
			G[u - 1].push_back(v - 1);
		}
	}
	t = 1;
	bool flag;
	do {
		flag = false;
		for (int i = 0; i < n; i++) {
			if (!used[i]) {
				DFS(i);
				flag = true;
				break;
			}
		}
	} while (flag);
	for (int i = 0; i < n; i++) {
		cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

ll t = 0;
vector <vector <bool>> v(100, vector <bool> (100, 0));
vector <ll> color(100);
vector <ll> start(100);
vector <ll> finish(100);

void dfs(ll i) {
  color.at(i) = 1;
  t++;
  start.at(i) = t;
  rep(j, color.size()) {
    if (v.at(i).at(j) == 0) continue;
    if (color.at(j) == 0) dfs(j);
  }
  color.at(i) = 2;
  t++;
  finish.at(i) = t;
  return;
}

int main() {
  ll n;
  cin >> n;
  rep(i, n) {
    ll a, b, c;
    cin >> a >> b;
    rep(j, b) {
      cin >> c;
      if (a != c) {
        v.at(a-1).at(c-1) = 1;
      }
    }
  }
  rep(i, n) color.at(i) = 0;
  rep(i, n) {
    if (color.at(i) == 0) dfs(i);
  }
  rep(i, n) cout << i+1 << ' ' << start.at(i) << ' ' << finish.at(i) << endl;
}

C++: #include <array>
#include <vector>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

int n;
int mat[100][100];
int d[100];
int f[100];

int dfs(int i, int t)
{
    d[i] = t++;

    REP(j, n) {
        if(mat[i][j] && !d[j]) {
            t = dfs(j, t);
        }
    }

    f[i] = t++;

    return t;
}

void solve()
{
    int t = 1;

    REP(i, n) {
        if(d[i]) continue;

        t = dfs(i, t);
    }
}

int main()
{
    cin >> n;

    REP(i, n) {
        REP(j, n) {
            mat[i][j] = 0;
        }
    }

    REP(_, n) {
        int u, k;
        cin >> u >> k;

        REP(_, k) {
            int v;
            cin >> v;
            mat[u-1][v-1] = 1;
        }
    }

    fill(begin(d), end(d), 0);
    fill(begin(f), end(f), 0);
    solve();

    REP(i, n) {
        cout << i+1 << " " << d[i] << " " << f[i] << "\n";
    }

    return 0;
}

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

const int N = 100;
int M[N][N];
int n;
int t;
int color[N];
int d[N], f[N];

void init(){
  for(int i=0;i<n;i++){
    color[i] = 0;
  }
}

void dfs(int x){
  color[x] = 1;
  d[x] = ++t;
  for(int i=0;i<n;i++){
    if(M[x][i] == 1 && color[i] == 0){
      dfs(i);
    }
  }
  color[x] = 2;
  f[x] = ++t;
}

int main(){
  cin >> n;
  int u, k, v;
  for(int i=0;i<n;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >> v;
      M[u-1][v-1] = 1;
    }
  }
  init();
  dfs(0);
  for(int i=0;i<n;i++){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n, u;
int k[110];
int a[110][110];
int b[110];
int d[110], f[110];
int t=1;

void dfs(int v)
{
	d[v]=t;
	t++;
	b[v]++;
	for(int l=0; l<k[v]; l++)
	{
		if(b[a[v][l]]==0)
		{
			dfs(a[v][l]);
		}
	}
	f[v]=t;
	t++;
}

int main() 
{
	cin >> n;
	for(int i=0; i<n; i++)
	{
		cin >> u;
		cin >> k[u];
		for(int j=0; j<k[u]; j++)
		{
			cin >> a[u][j];
		}
	}
	for(int v=1; v<=n; v++)
	{
		if(b[v]==0)
		{
			dfs(v);
		}
		cout << v << ' ' << d[v] << ' ' << f[v] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
using ll = long long;
using namespace std;

#define WHITE 1
#define GRAY 2
#define BLACK 3

int now, n, u, k, v, tree[102][102], timeTable[102][2], color[102], timeNow = 1;
stack<int> st;

void dfs(){
    while(1){
        if(st.empty()){
          	int l = 1;
          	while(1){
              	if(l == n + 1){
                	FOR(l, 1, n + 1){
                		cout << l << " " << timeTable[l][0] << " " << timeTable[l][1] << endl;
            		}
                  	break;
                }
            	if(color[l] == WHITE){
                	st.push(l);
                  	timeNow++;
                  	break;
                }
              	l++;
            }
          	if(l == n + 1){
            	break;
            }
        }else{
            now = st.top();
          	if(color[now] == WHITE){
            	timeTable[now][0] = timeNow;
            }
            color[now] = GRAY;
            int cnt = 1;
            while(1){
                if(cnt == n + 1){
                    st.pop();
                    color[now] = BLACK;
                    timeTable[now][1] = timeNow + 1;
                    break;
                }else if(tree[now][cnt] && color[cnt] == WHITE){
                    st.push(cnt);
                    break;
                }
                cnt++;
            }
            timeNow++;
        }
    }
}

int main(){
    cin >> n;
  	REP(i, 102){
    	REP(j, 102){
        	tree[i][j] = 0;
        }
    }
    REP(i, n){
        cin >> u >> k;
        color[i + 1] = WHITE;
        REP(j, k){
            cin >> v;
            tree[u][v] = 1;
        }
    }
    st.push(1);
    dfs();
  	return 0;
}