Go: package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include<cstdio>

bool table[102][102] = {};
int color[102] = {}; //0:?????¢?´¢???1:?¨??????????, 2:??¢?´¢??????
int n, counter = 0;
int t_visit[102] = {};
int t_finish[102] = {};

void DFS(int y) {
	
	for (int j = 0; j <= n - 1;j++) {

		//?¨????or??¢?´¢???????????£???????????????
		if ((table[y][j] == 1)&&(color[j] == 0)) {
			color[y] = 1; //?¨???????????????????
			if (t_visit[y] == 0) t_visit[y] = ++counter;
			DFS(j);
		}

	}

	color[y] = 2; //??¢?´¢???????????????
	if (t_visit[y] == 0) t_visit[y] = ++counter;
	if (t_finish[y] == 0) t_finish[y] = ++counter;
	
}

int main(void) {
	int u, k, s;

	scanf("%d", &n);

	for (int i = 0;i <= n - 1;i++) {
		scanf("%d %d", &u, &k);
		for (int j = 0;j <= k - 1;j++) {
			scanf("%d", &s);
			table[u - 1][s - 1] = 1;
		}
	}

	DFS(0);

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

	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];

//????????????????????????u?????????v
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;

    //??\????????????u?????????????????±?????????????´¢
    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();
}

C++: #include <iostream>
using namespace std;
int t = 1;
int d[100], f[100];
int a[100][100];
int N;
void dfs(int cur) {
 d[cur] = t;
 t++;
 for (int i=0; i<N; i++) {
  if (a[cur][i] == 1 && d[i] == 0) {
   dfs(i);
  }
 }
 f[cur] = t;
 t++;
}

int main() {
 cin >> N;
 for (int i=0; i<N; i++) {
  for (int j=0; j<N; j++) {
   a[i][j] = 0;
  }
  d[i] = 0;
  f[i] = 0;
 }
 for (int i=0; i<N; i++) {
  int u, k;
  cin >> u >> k;
  for (int j=0; j<k; j++) {
   int v;
   cin >> v;
   a[u-1][v-1] = 1;
  }
 }
 for (int i=0; i<N; i++) {
  if (d[i] == 0) { dfs(i); }
 }
 for (int i=0; i<N; i++) {
  cout << i+1 << " " << d[i] << " " << f[i] << endl;
 }
}

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() {
  //init
  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(void) {
  int u, k, v;
  cin >> n;
  //init
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }


  //??£??\???????????¨??????0-origin?????£??\???????????????
  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++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int, int>;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

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] == WHITE) {
            dfs_visit(v);
        }
    }

    color[u] = BLACK;
    f[u] = ++tt; // 訪問の完了
}

void dfs() {
    int u;
    // 初期化
    for (u = 0; u < n; ++u) color[u] = WHITE;
    tt = 0;

    for (u = 0; u < n; ++u) {
        // 未訪問の u を始点として深さ優先探索
        if (color[u] == WHITE) 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;
}