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 <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]++;
            g[v][u]++;
        }
    }
    stack<int> dfs;
    int time = 1;
    dfs.push(1);
    d[1] = time;
    while(!dfs.empty()){
        int u = dfs.top();
        bool flag = false;
        for(int i = 1;i <= n;i++){
            if(g[u][i] && d[i] == 0) {
                dfs.push(i);
                time++;
                d[i] = time;
                flag = true;
            }
        }
        if(!flag){
            dfs.pop();
            time++;
            f[u] = time;
        }
    }
    for(int i = 1;i <=n;i++) {
        cout << i << " " << d[i] << " " << f[i] <<endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#define N 100
#define  GRAY 1
#define BLACK 2
using namespace std;
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(int i = 0;i<n;i++)
    for(int j = 0;j<n;j++)
        M[i][j] = 0;
  for(int i =0;i<n;i++)
   {
     scanf("%d %d",&n,&k);
     u--;
     for(int j = 0;j<n;j++)
       {
         scanf("%d",&v);
         v--;
         M[u][v] = 1;
       }
   }
   dfs();
  return  0 ;
}

C++: #include <iostream>
#include <stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

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

void dfs_visit(int r) {
    for(int i = 0; i < n; i++) nt[i] = 0;
    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;
    while( !S.empty()) {
        int u = S.top();
        int v = next(u);
        if(v != -1) {
            if(color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}

void dfs() {
    for(int i = 0; i < n; i++) {
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;
    for(int u = 0; u < n; u++) {
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(int i = 0; i < n; i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

int main() {
    int u, k, v;
    cin >> n;
    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++) {
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    dfs();
    return 0;
}

C++: #if 0
????????????????????????????????????
?????¬??????????????????1?????????????????§?????????????????£????????°?????????????????????????????????????????????
????????????????????????for?????????if???????????¨????????§?????????
????????¨???????????°???????????¨???????????????????????¨????????§??????
??±???????????¢?´¢?????????????????????????????\????????????????????????????????????
??\??????c??§??±???????????????????????????????????¨???????????????????????????????????????????????°????????\????????????????????????????????£?????§??????
#endif
#include <iostream>
#include <queue>
using namespace std;
int D[105] = {0};
int V[105];
queue<int> Q[105];
int Ntime=0;
int n,u,k,v;
int d[105] = {0};//start time
int f[105] = {0};//end time
void dfs(int cur) { // cur????¨????
  // cur ????¨??????????????¨????
  Ntime += 1;
  // ???????¢??????¨??¨???
  //cerr << "visiting " << cur << ' ' << Ntime << endl;
  if(D[cur] == 0)
      d[cur] = Ntime;

  for(int dst = 1; dst <= n; dst++) { // ??¨???????????? dst ????????????
    if (D[cur] == 0&&Q[cur].size()>0 && Q[cur].front() == dst && D[dst] == 0) { // cur??????dst??????????????????,dst???????¨??????????
      if(dst != cur && d[dst] == 0)
          dfs(dst);
      Q[cur].pop();
	}
      if(D[cur] == 0&&Q[cur].size()>0 && Q[cur].front() == dst && D[dst] == 1)
          Q[cur].pop();
  }
  // cur ????¨????????????????????¨????
      Ntime += 1;
    if(D[cur] == 0){
        f[cur] =  Ntime;
        D[cur] = 1;}
  // ??¢??°?????????????????????????????? (?????¢??°)
}
int main(){
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> u >> k;
    V[i] = i;
    for(int j = 1; j <= k; j++){
      cin >> v;
      Q[u].push(v);     
    }
  }

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


}

C++: #include <cstdio>

typedef struct vertex_{
    int found;
    int d;
    int f;
}vertex;

int search(vertex *array, int (*A)[101], int id, int n, int time){
    if(array[id].found)return time;
    array[id].found=1;
    array[id].d=++time;
    for(int i=1;i<=n;i++){
        if(A[id][i])time=search(array,A,i,n,time);
    }
    array[id].f=++time;
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    vertex array[n+1];
    for(i=1;i<=n;i++)array[i].found=0;
    int A[101][101];
    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=0;j<k;j++){
            scanf("%d",&v);
            A[u][v]=1;
        }
    }
    int time = search(array, A, 1, n, 0);
    for(i=1;i<=n;i++)printf("%d %d %d\n",i,array[i].d,array[i].f);
    return 0;
}