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>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;
using Graph=vector<vector<int>>;

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

    int N; cin>>N;
    Graph G(N);
    for(int i=0;i<N;i++){
        int u,k; cin>>u>>k;
        u--;
        while(k--){
            int v; cin>>v;
            v--;
            G[u].push_back(v);
        }
    }
    vector<int> d(N,-1),f(N);
    int time=1;
    function<void(int)> dfs=[&](int v)
    {
        d[v]=time++;
        for(int u:G[v]) if(d[u]==-1){
            dfs(u);
        }
        f[v]=time++;
    };

    for(int i=0;i<N;i++) if(d[i]==-1){
        dfs(i);
    }
    for(int i=0;i<N;i++){
        cout<<i+1<<' '<<d[i]<<' '<<f[i]<<endl;
    }
    return 0;
}

C++: #include <stdio.h>

int A[101][101];
int ans[101][3];
int an = 1;


int judge(int i, int j){
  if(ans[i][j] == 0){
    ans[i][j] = an;
    an++;
  }
}

int serch(int a[101][101], int  ni, int n){
  int  j;
  
  for(j=0; j<n; j++){
    if(A[ni][j] == 1){
      judge(j, 1);
      serch(A, j, n);
    }
  }
  judge(ni, 2);
}

int  main(){
  int i, j, k, n, x, y;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    for(j=0; j<n; j++)
      A[i][j] = 0;
    ans[i][0] = i+1;
  }
  
  for(i=0; i<n; i++){
    scanf("%d %d", &x, &y);
    for(j=0; j<y; j++){
      scanf("%d", &k);
      A[i][k-1] = 1;
    }
  }
  
  judge(0, 1);
  
  for(i=0; i<n; i++){
    if(A[0][i] == 1){
      judge(i, 1);
      serch(A, i, n);
    }
  }
  judge(0, 2);
  
  for(i=0; i<n; i++){
    for(j=0; j<3; j++){
      if(j>0)
        printf(" ");
      printf("%d", ans[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}

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

int N;
int a[110][110]={{0}};
int d[110][5]={{0}};
int T=1;

void dfs(int cur);

int main(){
        cin >> N;
        for(int i=0; i<N; i++){
                int v,n;
                cin >> v;
                cin >> n;
                for(int j=0; j<n; j++){
                        int V;
                        cin >> V;
                        a[v-1][V-1]=1;
                }
        }
        dfs(1);
        for(int i=0; i<N; i++){
                cout << i+1 << " ";
                for(int j=0; j<2; j++){
                        cout << d[i][j];
                        if(!j)cout << " ";
                }
        cout << endl;
        }
}


void dfs(int cur){
        d[cur-1][0]=T;
        T++;
        //cerr << "visiting_" << cur << " " << T << endl;
        for(int i=0; i<N; i++){
                if(a[cur-1][i] && !d[i][0]){
                        dfs(i+1);
                }
        }
        d[cur-1][1]=T;
        T++;
        if(cur>1)cur--;
}

C++: #include <iostream>
using namespace std;
int color[101],d[101],f[101],t;
int a[101][101]={};
// white 0 gray 1 brack 2
void DFSvisit(int n,int u){
    t++;
    d[u]=t;
    color[u]=1;
    for(int i=1;i<=n;i++){
        if(a[u][i]==1 && color[i]==0){
            DFSvisit(n,i);
        }
    }
    color[u]=2;
    t++;
    f[u]=t;
}
void DFS(int n){
    for(int i=1;i<=n;i++){
        color[i]=0;
    }
    t=0;
    for(int i=1;i<=n;i++){
        if(color[i]==0){
            DFSvisit(n,i);
        }
    }
}
int main(){
    int n,k,m,l;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>m>>k;
        for(int j=0;j<k;j++){
            cin>>l;
            a[m][l]=1;
        }
    }
    DFS(n);
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    return 0;
}