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<iostream>

int main(){

  int n,a;
  std::cin>>n;

  int Adj[100][100],adj[100][100]={0},find[100][2],back[100],depth[100]={0},endflag[100]={0},flag;
  int u[n],k[n],kcou=0,timenow=0,v,pred,prev,firstv;
  for(int i=0;i<n;i++){
    std::cin>>u[i];
    std::cin>>k[i];
    for(int j=0;j<k[i];j++){
      std::cin>>Adj[i][j];
    }
  }
	
	/*
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    	std::cout<<Adj[i][j]<<" ";
    }
  	std::cout<<"\n";
  }*/
	
	v=0;
	firstv=0;
	while(timenow<n*2){
		flag=0;
		if(find[firstv][0]!=NULL&&find[firstv][1]!=NULL){
			for(int i=0;i<n;i++){
				if(find[i][0]==NULL){
					//std::cout<<i<<"\n";
					firstv=i;
					v=i;
					break;
				}
			}
		}
		//std::cout<<v;
		///std::cout<<find[v][0]<<" "<<find[v][1];
		if(find[v][0]==NULL){
			timenow++;
			find[v][0]=timenow;
			flag=1;
			//std::cout<<flag<<" 1";
		}else if(find[v][1]==NULL){
			if(endflag[v]==1){
				timenow++;
				find[v][1]=timenow;
				flag=2;
			}
			//std::cout<<flag<<" 2";
		}else{
			v=back[v];
			flag=3;
			//std::cout<<flag<<" 0";
		}

		if(flag==0){
			pred=depth[v];
			depth[v]++;
			prev=v;
			v=Adj[v][pred]-1;
			back[v]=prev;
			//std::cout<<flag<<"\n";
		}else if(flag==1){
			if(endflag[v]==0){
				if(Adj[v][depth[v]]-1!=v&&Adj[v][depth[v]]-1!=firstv){
					pred=depth[v];
					depth[v]++;
					prev=v;
					v=Adj[v][pred]-1;
					back[v]=prev;
					//std::cout<<v<<"\n";
				}else{
					pred=depth[v];
					depth[v]++;
				}
			}
		}else if(flag==2){
			v=back[v];
			//std::cout<<flag<<"\n";
		}
		if(depth[v]>k[v]-1){
			endflag[v]=1;
		}
		
	}
	
	
	
	
  for(int i=0;i<n;i++){
     std::cout<<i+1<<" "<<find[i][0]<<" ";
     std::cout<<find[i][1]<<"\n";
    //std::cout<<"\n";
  }

  return 0;
}

C++: #include<cstdio>

int G[110][110]={};
int d[110];
int f[110];

int cnt = 0;

void dfs(int i, int n)
{
  int j;

  d[i] = ++cnt;
  for(j = 1;j <= n;j++){
    if(G[i][j] != 1) continue;
    else G[i][j] = 0;
    
    if(d[j] == 0) dfs(j, n);
  }
  f[i] = ++cnt;
}

int main()
{
  int n;
  int i,j;
  int u,k,v;
  
  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d%d", &u, &k);

    for(j = 0;j < k;j++){
      scanf("%d", &v);
      G[u][v] = 1;
    }
  }

  for(i = 1;i <= n;i++)
    if(d[i] == 0) dfs(i, n);

  for(i = 1;i <= n;i++)
    printf("%d %d %d\n", i, d[i], f[i]);
  
  return 0;
}

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

using namespace std;

int n;
vector<vector<int>> g; 
int time = 0;
vector<int> d, f;
 
void dfs(int node){
    time++;

    if(d[node] == 0){
        d[node] = time;
    }

    for(auto next : g[node]){
        if(d[next] == 0){
            dfs(next);
        }
    }
    
    time++;
    if(f[node] == 0){
        f[node] = time;
    }
    return;
}
    
int main(){
    
    cin >> n;

    d.assign(n + 1, 0);
    f.assign(n + 1, 0);

    g.assign(n + 1, vector<int>());

    for(int i = 0; i < n; i++)
    {
        int nod, numOut;
        cin  >> nod >> numOut;
        for(int j = 0; j < numOut; j++)
        {
            int temp;
            cin >> temp;
            g[nod].push_back(temp);
        }
    }
    
    dfs(1);

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

    return 0;
}

C++: #include <stdio.h>
#include <string.h>
#define N 110
int n;
int m[N][N];
int used[N];
int time = 1;
int start[N];
int end[N];
void dfs(int u){
    used[u] = 1;
    start[u] = time++;
    for(int v = 1; v <= n; v++){
        if(used[v] == 0 && m[u][v]){
            dfs(v);
        }
    }
    end[u] = time++;
}
int main(){
    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++) used[i] = 0;
    scanf("%d", &n);
    for(int p = 0; p < n; p++){
        int node, k;
        scanf("%d %d", &node, &k);
        for(int i = 0; i < k; i++){
            int b;
            scanf("%d", &b);
            m[node][b] = 1;
        }
    }

    for(int i = 1; i<= n; i++) if(used[i] == 0) dfs(i);
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, start[i], end[i]);
    }
    return 0;
}

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

#define MAX 100

#define WHITE 0
#define GRAY 1
#define BLACK 2

int T;
int N;

int M[MAX][MAX];
int D[MAX], F[MAX], C[MAX];

void dfs(int u)
{
    C[u] = GRAY;
    D[u] = ++T;

    for (int i = 0; i < N; i++)
    {
        if(M[u][i] == 1 && C[i] == WHITE)
        {
            dfs(i);
        }        
    }
    C[u] = BLACK;
    F[u] = ++T;
}

int main ()
{
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        D[i] = 0;
        F[i] = 0;
        C[i] = WHITE;
        
        for (int j = 0; j < N; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < N; i++)
    {
        int u, k;
        cin >> u >> k;
        u--;

        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (j > 0)
                cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }

    T = 0;

    for (int i = 0; i < N; i++)
    {
        if (C[i] == WHITE)
        {
            dfs(i);
        }
    }

    /*
    stack<int> *S = new stack<int>;


    S->push(0);
    C[0] = GRAY;
    D[0] = ++time;

    while (S->size() > 0)
    {
        int u = S->top();
        int v = -1;

        // next 
        for (int i = 0; i < N; i++)
        {
            if (M[u][i] == 1)
            {
                if (C[i] == WHITE)
                {
                    v = i;
                    break;
                }
            }
        }

        if (v != -1)
        {
            C[v] = GRAY;
            D[v] = ++time;
            S->push(v);
        }
        else
        {
            S->pop();
            C[u] = BLACK;
            F[u] = ++time;
        }
    }
*/

    for (int i = 0; i < N; i++)
    {
        cout << i + 1 << " " << D[i] << " " << F[i] << endl;
    }
    return 0;
}