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 <cstdio>
#include <vector>
using namespace std;

const int maxn = 100;
vector<int> G[maxn + 5];
//int book[maxn + 5][maxn + 5];
int n;
int d[maxn + 5];
int f[maxn + 5];
int time = 0;


void dfs(int vertex) {
    d[vertex] = ++time;

    int len = G[vertex].size();
    for(int i = 0; i < len; i++) {
        if(!d[G[vertex][i]]) dfs(G[vertex][i]);
    }

    f[vertex] = ++time;
}

int main() {
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        int num;
        scanf("%d", &num);
        int count;
        scanf("%d", &count);


        while(count--) {
            int temp; scanf("%d", &temp);
            G[num].push_back(temp);
        }
    }
    for(int i = 1; i <= n; i++) {
        if(!d[i]) dfs(i);
    }

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

C++: #include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <complex>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int d[110], f[110];
vector<int> g[110];
int t;
bool used[110];
void solve(int i) {
    if (used[i]) return;
    used[i] = true;
    t++;
    d[i] = t;
    for (int j: g[i]) {
        solve(j);
    }
    t++;
    f[i] = t;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int id, u;
        cin >> id >> u;
        for (int j = 0; j < u; j++) {
            int a;
            cin >> a;
            g[i].push_back(a-1);
        }
    }
    t = 0;
    fill_n(used, 110, false);
    for (int i = 0; i < n; i++) {
        solve(i);
    }
    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }
    return 0;
}

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

#define M 100
#define TRUE 10
#define WHITE 1
#define BLACK 2
#define GRAY 3
stack<int> T;
int n,t = 1,D[M + 1],F[M + 1],color[M + 1],N[M + 1][M + 1],Ni[M + 1];

int next(int v){
  for(int i = Ni[v];i <= n;i++){
    Ni[v] = i + 1;
    if(N[v][i] == TRUE) return i;
  }
  return -1;
}
  
void dsearch(int v){
  int top;
  
  T.push(v);
  color[v] = GRAY;
  D[v] = t++;

  while(!T.empty()){
    v = T.top();
    top = next(v);
    if(top != -1){
      if(color[top] == WHITE){
	color[top] = GRAY;
	D[top] = t++;
	T.push(top);
      }
    }
    else{
      T.pop();
      color[v] = BLACK;
      F[v] = t++;
    }
  }
}
  
int main (){
  int r,c,v;

  cin >> n;
  for(int i = 1;i <= n;i++){
    color[i] = WHITE;
    Ni[i] = 0;
  }
 
  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= n;j++){
      N[i][j] = 0;
    }
  }
  
  for(int i = 1;i <= n;i++){
    cin >> r >> c;
    for(int j = 1;j <= c;j++){
      cin >> v;
      N[r][v] = TRUE;
    }
  }
  for(int i = 1;i <= n;i++){
    if(color[i] == WHITE) dsearch(i);
  }
  for(int i = 1;i <= n;i++){
    cout << i << " "<< D[i] << " "<< F[i] << endl;
  }

  return 0;
}

C++: 
#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;


vector<int> G[105];
int d[105];
int f[105];
int tm = 1;
void dfs(int p){
    d[p]=tm;
    rep(i,G[p].size()){
        if(d[G[p][i]]==-1){
            tm++;
            dfs(G[p][i]);
        }
    }
    f[p] = tm++;
    return;
}
int main(int argc, const char * argv[])
{
    int n;
    cin >> n;
    for(int i = 0;i <= n;i++) {
        d[i]=-1;
        f[i]=-1;
    }
    for(int i = 0;i < n;i++){
        int u,k;
        int to;
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&to);
            G[u].push_back(to);
        }
    }
    dfs(1);
    for(int i = 1;i <= n;i++){
        printf("%d %d %d\n",i,d[i],f[i]);
    }
}

C++: #include <cstdio>

int n, G[100][100], d[100], f[100], checked[100], time;

void dfs_visit(int u) {
    int i;
    checked[u] = 1;
    d[u] = ++time;
    for (i = 0; i < n; i++) {
        if (G[u][i] == 0) continue;
        if (checked[i] == 0) dfs_visit(i);
    }
    f[u] = ++time;
}

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

    for (i = 0; i < n; i++) {
        if (checked[i] == 0) dfs_visit(i);
    }
}

int main(void) {
    int u, k, v, i, j;
    scanf("%d", &n);
    
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++) G[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--;
            G[u][v] = 1;
        }
    }

    dfs();

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

    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;
    }
  }
  
  for(j=0; j<n; j++){
  judge(j,1);
    for(i=0; i<n; i++){
      if(A[0][i] == 1){
        judge(i, 1);
        serch(A, i, n);
      }
    }
    judge(j, 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;
}