Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	t := 1
	for i := 1; i <= n; i++ {
		t = dfs(&g, &d, &f, i, t)
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

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

C++: #include<iostream>
#include<string>
#include<stack>
#include<unordered_set>
#include<algorithm>

#define N 1000

int n, u, k, v;
int G[N][N];
std::stack<int> S;
std::unordered_set<int> hasVisited;
int count, d[N], f[N];

void visit(int x) {
    hasVisited.insert(x);
    d[x] = count++;
    for(int i = 1; i <= n; i++) {
        if(G[x][i] != 0 && hasVisited.find(i) == hasVisited.end()) {
            visit(i);
        }
    }
    f[x] = count++;
}

int main() {

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            G[i][j] = 0;
        }
    }
    std::cin >> n;
    for(int i = 0; i < n; i++) {
        std::cin >> u >> k;
        for(int j = 0; j < k; j++) {
            std::cin >> v;
            G[u][v] = 1;
        }
    }

    count = 1;
    for(int i = 0 ; i < N; i++) {
        d[i] = 0;
        f[i] = 0;
    }

    for(int i = 1; i <= n; i++) {
        if(hasVisited.find(i) == hasVisited.end())
            visit(i);
    }
    for(int i = 1; i <= n; i++) {
        printf("%i %i %i\n", i, d[i], f[i]);
    }

    return 0;
}

C++: //
// Created by tattsun on 2017/02/13.
//

#include <iostream>
#include <vector>

using namespace std;

#define VERTEX_MAX_NUM 101
#define NIL -1

int now = 0;
int n;
int start[VERTEX_MAX_NUM];
int finish[VERTEX_MAX_NUM];
bool visited[VERTEX_MAX_NUM];
vector<int> vertexes[VERTEX_MAX_NUM];

void _dfs(int node) {
    start[node] = ++now;
    visited[node] = true;

    auto& v = vertexes[node];

    for(auto it = v.begin(); it != v.end(); it++) {
        if(visited[*it])
            continue;
        _dfs(*it);
    }

    finish[node] = ++now;
}

void dfs() {
    for(int i=1; i<=n; i++) {
        if(visited[i]) continue;
        _dfs(i);
    }
}

int main() {
    for(int i=0; i<VERTEX_MAX_NUM; i++) {
        start[i] = NIL;
        finish[i] = NIL;
        visited[i] = false;
    }

    cin >> n;

    int u, k, p;
    for(int i=1; i<=n; i++) {
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            cin >> p;
            vertexes[i].push_back(p);
        }
    }

    dfs();

    for(int i=1; i<=n; i++) {
        cout << i << " " << start[i] << " " << finish[i] << endl;
    }
}

C++: #include <bits/stdc++.h>

int d[128];
int f[128];
bool c[128][128];
int n;
int t;
int checked[128];

void dfs(int i) {
  if( checked[i] ) return;
  checked[i] = true;
  t += 1;
  d[i] = t;
  for(int k = 1; k <= n; ++k) {
    if( c[i][k] ) {
      dfs(k);
    }
  }
  t += 1;
  f[i] = t;
  return;
}

int main(void) {

  for(int i = 0; i < 128; ++i) {
    for(int j = 0; j < 128; ++j) {
      c[i][j] = false;
    }
  }

  std::cin >> n;

  int u, k, v;
  for(int i = 0; i < n; ++i) {
    std::cin >> u >> k;
    for(int j = 0; j < k; ++j) {
      std::cin >> v;
      c[u][v] = true;
    }
  }

  dfs(1);

  for(int i = 1; i <= n; ++i) {
    std::cout << i << " " << d[i] << " " << f[i] << std::endl;
  }
  return 0;
}