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 <stack>
using namespace std;

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

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

    int M[N][N];
    int D[N], F[N], C[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;
    }
*/
    stack<int> *S = new stack<int>;

    int time = 0;

    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++)
        {
            int flag = M[u][i];

            if (flag == 1)
            {
                if (C[i] == WHITE)
                {
                    v = i;
                    break;
                }
            }
        }

        if (v != -1)
        {
            if (C[v] == WHITE)
            {
            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;
}

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


void solve(int);

typedef struct{
  int k;
  vector<int> ls;
  int f,d;
}node_t;

node_t node[101];
int t=0;

int main(){
  int n;
  int u;

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> u; 
    cin >> node[u].k;
    node[u].ls.resize(node[u].k);
    node[u].d = node[u].f = -1;
    for(int j=0; j<node[u].k; j++){
      cin >> node[u].ls[j];
    }
    sort(node[u].ls.begin() , node[u].ls.end());
  }
 
  for(int i=0; i<n; i++)
    solve(i+1);

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

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % 2019;
    } else {
        return modpow(m, n - 1) * m % 2019;
    }
}
long long n;
vector<bool> visited(100, false);
vector<int> t1(100);
vector<int> t2(100);
vector<vector<long long>> graph(100);
int ts = 1;
void dfs(int cur) {
    visited[cur] = true;
    t1[cur] = ts;
    ts++;
    for (int i = 0; i < graph[cur].size(); i++) {
        if (visited[graph[cur][i]] == false) {
            dfs(graph[cur][i]);
        }
    }
    t2[cur] = ts;
    ts++;
}
signed main() {
    cin >> n;
    for (long long i = 0; i < n; i++) {
        long long s, k;
        cin >> s >> k;
        for (int j = 0; j < k; j++) {
            int l;
            cin >> l;
            graph[s - 1].push_back(l - 1);
        }
    }
    REP(i, n) {
        if (!visited[i]) {
            dfs(i);
        }
    }
    REP(i, n) { cout << i + 1 << " " << t1[i] << " " << t2[i] << endl; }
}

C++: #include<stdio.h>
#include<stdlib.h>
#define N 102
#define white 0
#define gray 1
#define black 2

int n,color[N],d[N],f[N],S[N],top=0,t=0,nt[N],a[N][N];

void push(int x){
  if(top==N){
    printf("Stack overflow!\n");
    exit(2);
  }
  S[++top]=x;
}

int pop(void){
  if(top==0){
    printf("Stack is empty!\n");
    exit(3);
  }
  top--;
  return S[top+1];
}

int next(int u){
  int v;
  for(v=nt[u];v<=n;v++){
    nt[u]=v+1;
    if(a[u][v]) return v;
  }
  return -1;
}

void dfs(int r){
  int i;
  for(i=1;i<=n;i++) nt[i]=0;

  push(r);
  color[r]=gray;
  d[r]=++t;

  while(S[top]!=0){
    int u=S[top],v=next(u);

    if(v!=-1){
    if(color[v]==white){
      color[v]=gray;
      d[v]=++t;
      push(v);
    }
    }
    else {
      pop();
      color[u]=black;
      f[u]=++t;
    }
  }
}

void dfs_init(){
  int i,u;
  for(i=1;i<=n;i++){
    color[i]=white;
  }
  t=0;

  for(u=1;u<=n;u++){
    if(color[u]==white) dfs(u);
  }

}

void print(){
  int i;
  for(i=1;i<=n;i++) printf("%d %d %d\n",i,d[i],f[i]);
}

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      a[i][j]=0;
    }
  }

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

  dfs_init();
  print();


  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int cnt=1;
void depth(vector< vector<int> > &vv,vector<int> &f,vector<int> &c,int num){
	f[num]=cnt;
	cnt++;
	for(int i=0; i<vv[num].size(); i++){
		if(vv[num][i]!=0 && f[i]==0){
			depth(vv,f,c,i);
		}
	}
	if(c[num]==0){
		c[num]=cnt;
		cnt++;
	}
}
int main(){
	int n;
	cin>>n;
	vector< vector<int> > v(n,vector<int> (n,0));
	vector<int> ft(n,0);
	vector<int> ct(n,0);
	int u[n];
	for(int i=0; i<n; i++){
		int k;
		cin>>u[i]>>k;
		for(int j=0; j<k; j++){
			int x;
			cin>>x;
			v[i][x-1]=1;
		}
	}
	for(int i=0; i<n; i++){
		if(ft[i]==0){
			depth(v,ft,ct,i);
		}
	}
	for(int i=0; i<n; i++){
		cout<<u[i]<<" "<<ft[i]<<" "<<ct[i]<<endl;
	}
  return 0;
}