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"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<LL, LL>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<LL>;

//==============================================
int n, tt = 0;
vvi M;
vi D, F, searchStatus;

void antDfs(int u) {
	searchStatus[u] = 0;
	D[u] = ++tt;
	REP3(i, 1, n) {
		if (M[u][i] == 0) continue;

		if (searchStatus[i] == -1) {
			antDfs(i);
		}
	}
	F[u] = ++tt;
	searchStatus[u] = 1;
}

void print() {
	REP3(i, 1, n) {
		cout << i << " " << D[i] << " " << F[i] << "\n";
	}
}

void solve() {
	REP3(i, 1, n) searchStatus[i] = -1;

	REP3(i, 1, n) {
		if (searchStatus[i] == -1) {
			antDfs(i);
		}
	}

	print();
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	
	M.resize(n + 1, vi(n + 1));
	D.resize(n + 1);
	F.resize(n + 1);
	searchStatus.resize(n + 1);

	int u, k, v;
	REP3(i, 1, n) {
		cin >> u >> k;
		REP3(j, 1, k) {
			cin >> v;
			M[u][v] = 1;
		}
	}

	solve();
	return 0;
}

C++: #include<iostream>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 1

int n, M[N][N];
int color[N], s[N], f[N], ts; 

void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    s[u] = ++ts;
    for (v=0; v<n; v++) {
        if(M[u][v]==0){
            continue;
        }
        if (color[v]==WHITE) {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++ts;
}

void dfs() {
    int u;
    for (u=0; u<n; u++) {
        color[u] = WHITE;
    }
    ts = 0;
    //for (u=0; u<n; u++) {
    //    if (color[u]==WHITE){
            dfs_visit(0);
    //    }
    //}
    for (u=0; u<n; u++) {
        printf("%d %d %d\n", u+1, s[u], f[u]);
    }
}

int main() {
    int u, k, tmp;
    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;
        for (int j=0; j<k; j++) {
            cin >> tmp;
            M[u-1][tmp-1] = 1;
        }
    }
    dfs();
    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n, m[N][N];
int color[N], d[N], f[N], tt;
void dfs_visit(int u) {
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	for (v = 0; v < n; v++) {
		if (m[u][v] == 0)continue;
		if (color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}
void dfs() {
	int u;
	for (u = 0; u < n; u++)color[u] = WHITE;
	tt = 0;
	for (u = 0; u < n; u++) {
		if (color[u] == WHITE)dfs_visit(u);
	}
	for (u = 0; u < n; u++) {
		printf("%d %d %d\n", u + 1, d[u], f[u]);
	}
}
int main() {
	int u, v, k, i, j;
	cin >> n;
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			m[i][j] = 0;
		}
	}
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		u--;
		for (j = 0; j < k; j++) {
			cin >> v;
			v--;
			m[u][v] = 1;
		}
	}
	dfs();
	return 0;
}

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


vector<bool> seen;
vector<int> first_order;
vector<int> last_order;

void dfs(const vector<vector<int>> &G, int v, int& time){
	first_order[v] = time++;
	seen[v] = true;
	for(auto next_v:G[v]){
		if(seen[next_v]) continue;
		dfs(G, next_v, time);
	}
	last_order[v] = time++;
}

int main()
{
	int n;
	cin>>n;
	vector<vector<int>> G(n+1);
	for(int i=1;i<n+1;i++){
		int a, b, c;
		cin>>a>>b;
		for(int j=0;j<b;j++){
			cin>>c;
			G[a].push_back(c);
		}
	}
	seen.assign(n+1, false);
	first_order.resize(n+1);
	last_order.resize(n+1);
	int time = 1;
	for(int i=1;i<n+1;i++){
		if(seen[i]) continue;
		dfs(G, i, time);
	}
	
	for(int i=1;i<n+1;i++){
		cout<< i << " " << first_order[i] << " " << last_order[i] << endl;
	}
}

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

using namespace std;

int curTime = 1;
void dfs(int cur, const vector<vector<bool> >& a, vector<int>& d, vector<int>& f, vector<bool>& visited){
  visited[cur] = true;
  d[cur] = curTime;
  curTime++;
  // cerr << "visiting [" << cur << "], time = " << curTime << endl;

  for(int dst = 1; dst <= a.size(); dst++){
    if(a[cur][dst] && !visited[dst]) {// cur????????¶??????????????????????????????
      dfs(dst, a, d, f, visited);
    }
  }
  f[cur] = curTime;
  curTime++;
  return;
}

int main(){
  int n;
  cin >> n;
  vector<vector<bool> > a(n+1, vector<bool>(n+1, false));
  for(int i = 1; i <= n; i++){
    int u;
    cin >> u;
    int k;
    cin >> k;
    for(int j = 0; j < k; j++){
      int v;
      cin >> v;
      a[i][v] = true;
    }
  }

  vector<bool> visited(n+1, false);
  vector<int> d(n+1), f(n+1);

  dfs(1, a, d, f, visited);

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

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> F[102];
int start[102]={0},END[102]={0};
bool visit[102]={0};
int Count=0;
void dfs(int now){
	start[now]=Count++;
	visit[now]=true;
	int len=F[now].size();
	for(int i=0;i<len;i++){
		int p=F[now][i];
		if(visit[p]==false){
		     dfs(p);
		}
	}
	END[now]=Count++;
}
int main() {
	int n;
    cin>>n;
    for (int i=0;i<n;i++) {
            int s,num;
            cin>>s>>num;
            s--;
            for (int j=0;j<num;j++) {
                int e;
                cin>>e;
                e--;
				if(e!=s){
					F[s].push_back(e);
				}
            }
        }
        for (int i=0;i<n;i++){
			if(visit[i]==false){
				dfs(i);
			}
        }      
        for (int i = 0; i < n;i++) {
            cout<<i+1<<" "<<start[i]+1<<" "<<END[i]+1<<endl;
        }
    return 0;
}