Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < N; i++ {
		u, k := sc.nextInt()-1, sc.nextInt()
		for j := 0; j < k; j++ {
			G[u] = append(G[u], sc.nextInt()-1)
		}
	}
	ans := make([][2]int, N)
	time := 0
	found := make(map[int]bool)
	var dfs func(cur int)
	dfs = func(cur int) {
		time++
		ans[cur][0] = time
		found[cur] = true
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if !found[next] {
				dfs(G[cur][i])
			}
		}
		time++
		ans[cur][1] = time
	}
	for i := 0; i < N; i++ {
		if !found[i] {
			dfs(i)
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprint(wtr, i+1)
		for j := 0; j < 2; j++ {
			fmt.Fprint(wtr, " ")
			fmt.Fprint(wtr, ans[i][j])
		}
		fmt.Fprintln(wtr)
	}
	wtr.Flush()
}

C++: #include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

int g[101][101],n,d[101],f[101];

int main() {
    cin >> n;
    for(int i = 0;i < n;i++) {
        int u,k,v;
        cin >> u >> k;
        for(int j = 0;j < k;j++) {
            cin >> v;
            g[u][v]++;
        }
    }
    stack<int> dfs;
    int time = 2;
    dfs.push(1);
    d[1] = 1;
    bool flag = true;
    while(flag) {
        while (!dfs.empty()) {
            int u = dfs.top();
            bool fl = false;
            for (int i = 1; i <= n; i++) {
                if (g[u][i] && d[i] == 0 && u != i) {
                    dfs.push(i);
                    d[i] = time++;
                    fl = true;
                    break;
                }
            }
            if (!fl) {
                dfs.pop();
                f[u] = time++;
            }
        }
        flag = false;
        for(int i =1;i <= n;i++) if(d[i] == 0){flag = true;dfs.push(i);d[i] = time++;break;}
    }
    for(int i = 1;i <=n;i++) {
        cout << i << " " << d[i] << " " << f[i] <<endl;
    }
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int t;

void dfs(int pos, vector<int>& d, vector<int>& f, vector<vector<int>>& a){
	rep(i,a.size()){
		if(a[pos][i] == 1 and d[i] == -1){
			t++;
			d[i] = t;
			dfs(i, d, f, a);
		}
	}
	t++;
	f[pos] = t;
}

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

	vector<vector<int>> a(n, vector<int>(n,0));
	rep(i,n){
		int from;
		int m;
		cin >> from >> m;
		from--;
		rep(j,m){
			int to;
			cin >> to;
			to--;
			a[from][to] = 1;
		}
	}

	vector<int> d(n,-1), f(n);
	t = 1;
	d[0] = t;
	dfs(0, d, f, a);

	rep(i,n){
		cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

ll n, t = 0;
vector<vector<ll>> g;
vector<ll> d, f;

void dfs(ll v, ll p = -1) {
    if (d[v] != -1) return;
    t++;
    d[v] = t;
    rep(i, sz(g[v])) {
        if (g[v][i] == p) continue;
        dfs(g[v][i], v);
    }
    f[v] = t;
    t++;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n;
    g.resize(n);
    rep(i, n) {
        ll u, k;
        cin >> u >> k;
        u--;
        rep(j, k) {
            ll v;
            cin >> v;
            v--;
            g[u].push_back(v);
        }
    }
    rep(i, n) sort(all(g[i]));
    d.resize(n, -1);
    f.resize(n, -1);
    rep(i, n) {
        if (d[i] == -1) dfs(i);
    }
    rep(i, n) {
        printf("%lld %lld %lld\n", i + 1, d[i], f[i] + 1);
    }
    return 0;
}

C++: #if 0
????????£?????????????´??????????
?????°?????¨??????dfs??????????????????????°??????§?????????
#endif

#include <iostream>
#include <vector>
using namespace std;
vector<int> E[101];
bool visited[101];
int in[101];
int out[101];
int count=0;
int nv(int n)
{
    int i=1;
    for(i=1;i<=n;i++)
    {
        if ( visited[i]==false )
            return i;
    }
    if (i>n) return 0;
}

void dfs(int n)
{
    visited[n]=true;
    in[n]=++count;
    for(vector<int>::iterator it=E[n].begin();it!=E[n].end();++it)
    {
        int now=*it;
        if(visited[now]==false)
            dfs(now);
    }
    out[n]=++count;
}

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int e,n0;
        cin>>e>>n0;
        for(int j=0;j<n0;j++)
        {
            int t;
            cin>>t;
            E[e].push_back(t);
        }
        visited[i]=false;
        in[i]=out[i]=0;
    }

    int now=nv(n);
    while(now!=0)
    {
        dfs(now);
        now=nv(n);
    }


/*  for(int i=1;i<=n;i++)
    {
        for(vector<int>::iterator it=E[i].begin();it!=E[i].end();++it)
            cout<<*it<<" ";
        cout<<endl;
    }
*/
    for(int i=1;i<=n;i++)
        cout<<i<<" "<<in[i]<<" "<<out[i]<<endl;
    return 0;



}

C++: #include <iostream>

using namespace std;

	int TIME = 0;
	int d[101];
	int f[101];
	int num;
	int graph[101][101] = {0};

void dfs(int x){
	TIME++;
	d[x] = TIME;

	for(int i=1;i<=num;i++){
		if(graph[x][i] == 1 && d[i]==0){
			dfs(i);
		}
	}
	f[x] = ++TIME;
}

int main(){
	int hon;
	int eda;
	int ver;

	cin>>num;
	for(int i=0;i<num;i++){
		cin>>eda;
		cin>>hon;
		for(int j=0;j<hon;j++){
			cin>>ver;
			graph[eda][ver]++;
		}
	}

	dfs(1);

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

	return 0;
}