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++: //aizu
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
using namespace std;

vector <int> v[101];

pair <int, int> af[101];

bitset <101> viz;

int cnt;

void DFS(int nod)
{
    cnt++;
    af[nod].first = cnt;
    viz[nod] = 1;

    for (size_t i = 0; i < v[nod].size(); ++i)
    {
        if (viz[v[nod][i]] == 0)
            DFS(v[nod][i]);
    }
    cnt++;
    af[nod].second = cnt;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n, u, k, ind;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> u >> k;
        for (int j = 1; j <= k; ++j)
        {
            cin >> ind;
            v[u].push_back(ind);
        }
        sort(v[u].begin(), v[u].end());
    }

    for (int i = 1; i <= n; ++i)
        if (viz[i] == 0)
            DFS(i);

    for (int i = 1; i <= n; ++i)
        cout << i << " " << af[i].first << " " << af[i].second << "\n";
    return 0;
}

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

int N;
int a[110][110]={{0}};
int d[110][5]={{0}};
int T=1;

void dfs(int cur);

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


void dfs(int cur){
        d[cur-1][0]=T;
        T++;
        //cerr << "visiting_" << cur << " " << T << endl;
        for(int i=0; i<N; i++){
                if(a[cur-1][i] && !d[i][0])dfs(i+1);
        }
        d[cur-1][1]=T;
        T++;
        if(cur>1)cur--;
}

C++: #include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vvll edge(110, vll(0));
vll d(110, -1), f(110, -1);

void dfs(int n, int &time){
  if(edge.at(n).size() == 0){
    d.at(n) = time;
    time++;
    f.at(n) = time; time++;
    return;
  }
  d.at(n) = time; time++;
  bool flag = true;
  for(int i = 0; i < edge.at(n).size(); i++){
    if(d.at(edge.at(n).at(i)) == -1){
      dfs(edge.at(n).at(i), time);
    }
  }
  f.at(n) = time; time++;
}

int main(){
  int n;
  cin >> n;
  
  for(int i = 0; i < n; i++){
    int u, k;
    cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      ll v;
      cin >> v;
      v--;
      edge.at(u).push_back(v);
    }
  }
  int time = 1;
  for(int i = 0; i < n; i++){
    if(d.at(i) == -1) dfs(i, time);
  }
  
  for(int i = 0; i < n; i++){
    cout << i+1 << ' ' << d.at(i) << ' ' << f.at(i) << endl;
  }

}

C++: #include<cstdio>
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#define _USE_MATH_DEFINES // M_PI????????????????????????
#include<math.h>
#pragma warning(disable:4996)
using namespace std;

#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++){
		cout << u+1 << d[u] << f[u] << "\n";
	}
}

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

	for(i=0; i<n; i++){
		cin >> u >> k;
		u--;
		for(j=0; j<k; j++){
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	dfs();
	return 0;
}

C++: #include<stdio.h>
#define N 100

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

void dfs_visit(int);
void dfs();

static int n, M[N][N], color[N], d[N], f[N], tt;;

int main(){
  int u, k, v, 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++){
    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;
}

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  tt++;
  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 i, u;
  for (i = 0; i < n; i++){
      color[i] = WHITE;
  }
  tt = 0;
  for (u = 0; u < n; u++){
    if (color[u] == WHITE){
        dfs_visit(u);
    }
  }
  for (i = 0; i < n; i++){
    printf("%d %d %d\n", i+1, d[i], f[i]);
  }
}

C++: #include<stdio.h>
 
#define MAX 100
#define WHITE -1
#define GRAY 0
#define BLACK 1
 
int n,t;
int color[MAX],d[MAX],f[MAX],Adj[MAX][MAX];
 
dfs(){
  int i;
 
  for(i=0;i<n;i++) color[i]=WHITE;
  t=0;
  for(i=0;i<n;i++){
    if(color[i]==WHITE) visit(i);
  }
}
 
visit(int r){
  int i;
 
  color[r]=GRAY;
  d[r]=++t;
 
  for(i=0;i<n;i++){
    if(Adj[r][i]==1 && color[i]==WHITE) visit(i);
  }
 
  color[r]=BLACK;
  f[r]=++t;
}
 
int main(){
  int i,u,k,j,v;
 
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){ 
      Adj[i][j]=0;
    }
  }
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      Adj[u-1][v-1]=1;
    }
  }
 
  dfs();
 
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
 
  return 0;
}