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 <iostream>
#include <vector>
#include <stack>
#include <algorithm>

typedef struct {
	bool firstflag;
	bool endflag;
	int firsttime;
	int endtime;
}State;

const int Max = 100;
int map[Max + 1][Max + 1] = { 0 };
std::stack<int> st;
std::vector<State> state;


int main()
{
	int n, k, v, x;
	int cnt = 1;

	std::cin >> n;
	for (int i = 1; i <= n; i++) {
		std::cin >> x >> k;
		for (int j = 1; j <= k; j++) {
			std::cin >> v;
			map[x][v] = 1;
		}
	}

	State s = { false,false,0,0 };
	for (int i = 0; i <= n; i++) {
		state.push_back(s);
	}

	while (1) {
		if (st.empty() == true) {
			if (state[1].endflag == true) {
				bool flag = false;
				for (int i = 1; i <= n; i++) {
					if (state[i].firstflag == false) {
						st.push(i);
						state[i].firstflag = true;
						state[i].firsttime = cnt;
						cnt++;
						flag = true;
						break;
					}
				}
				if (flag == true) {
					continue;
				}
				else {
					break;
				}
			}
			else {
				st.push(1);
				state[1].firstflag = true;
				state[1].firsttime = cnt;
				cnt++;
				continue;
			}
		}

		bool flag = false;
		for (int i = 1; i <= n; i++) {
			if (map[st.top()][i] == 1) {
				if (state[i].firstflag == false) {
					st.push(i);
					state[i].firstflag = true;
					state[i].firsttime = cnt;
					cnt++;
					flag = true;
					break;
				}
			}
		}
		if (flag == true) {
			continue;
		}
		else {
			state[st.top()].endflag = true;
			state[st.top()].endtime = cnt;
			cnt++;
			st.pop();
		}
	}

	for (int i = 1; i <= n; i++) {
		std::cout << i << " " << state[i].firsttime << " " << state[i].endtime << std::endl;
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;
int MAX1=1;

void dfs(Graph &G, vector<int>&seen, vector<int>&done, int v, int cnt){
    seen[v]=MAX1++;
    for(auto next_v : G[v]){
        if(seen[next_v]!=0)continue;
        dfs(G,seen,done,next_v,cnt);
    }
    done[v]=MAX1++;
}

int main() {
    int n;
    cin>>n;
    Graph G(n);
    for(int i=0;i<n;i++){
        int u;
        cin>>u;
        int k;
        cin>>k;
        vector<int>a(k);
        for(int j=0;j<k;j++){
            cin>>a[j];
            a[j]--;
        }
        sort(a.begin(),a.end());
        G[u-1]=a;
    }
    // for(int i=0;i<n;i++){
    //     sort(G[i].begin(),G[i].end());
    // }
    vector<int>seen(n,0);
    vector<int>done(n,0);

    for(int i=0;i<n;i++){
        if(seen[i]==0){
            dfs(G,seen,done,i,0);
        }
    }

    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<seen[i]<<" "<<done[i]<<endl;
    }





    return 0;
}

C++: #include<stdio.h>
#define N 100
#define  GRAY 1
#define BLACK 2
#define WHITE 0
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] == 0)
    {
      dfs_visit(v);
    }
}
  color[u] = BLACK;
  f[u] == ++tt;
}
void dfs()
{
  int u;
  for(u = 0;u<n;u++)
     color[u] = 0;
  tt = 0;
  for(u = 0;u<n;u++)
  {
    if(color[u] == 0) 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;
  scanf("%d",&n);
  for( i = 0;i<n;i++)
  {  for( j = 0;j<n;j++)
        M[i][j] = 0; }
  for( i =0;i<n;i++)
   {
     scanf("%d %d",&u,&k);
     u--;
     for( j = 0;j<k;j++)
       {
         scanf("%d",&v);
         v--;
         M[u][v] = 1;
       }
   }
   dfs();
  return  0 ;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
#define MAX 100
#define WHITE 1
#define GRAY 2
#define BLACK 3

int n;
int graph[MAX][MAX];
stack<int> st;
int *d,*f,*v;
int *color;

int next(int k){
	for(int i = v[k];i < n;i++){
		v[k]++;
		if(color[i] == WHITE && graph[k][i] == 1) return i;
	}
	return -1;
}

void dfs(int k){
	for(int i = 0;i < n;i++) v[i] = 0;
	int time = 0;

	st.push(k);
	d[k] = ++time;
	color[k] = GRAY;

	while(!st.empty()){
		int m = next(st.top());
		if(m != -1){
		  if(color[m] == WHITE){
				st.push(m);
				color[m] = GRAY;
				d[m] = ++time;
			}
		}else{
			f[st.top()] = ++time;
			color[st.top()] = BLACK;
			st.pop();
		}
	}
}


int main(){
	cin >> n;
	//?????????
	color = new int[n];
	d = new int[n];
	f = new int[n];
	v = new int[n];
	for(int i = 0;i < n;i++){
		color[i] = WHITE;
		d[i] = 0;
		f[i] = 0;
		for(int j = 0;j < n;j++){
			graph[i][j] = 0;
		}
	}
	//data input
	for(int i = 0;i < n;i++){

		int t,k,p;

		cin >> t >>  k;
		for(int j = 0;j < k;j++){
			cin >> p;
			p--;
			graph[i][p] = 1;
		}
	}
	for(int i = 0;i < n;i++){if(color[i] == WHITE) dfs(i);}
	for(int i = 0;i < n;i++){
		cout << i+1 << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}