Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	n := len(list)
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list[0 : n-1] {
		buf.Write([]byte(fmt.Sprintf("%d ", v)))
	}
	buf.Write([]byte(fmt.Sprintf("%d\n", list[n-1])))
	buf.Flush()
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

//solve

const MAX = 100
const WHITE = 0
const GRAY = 1
const BLACK = 2

var time, n int

//隣接行列
var M [MAX][MAX]int

//d[i]: 最初にiを訪問した時刻。発見時刻
//f[i]: iの隣接リストを訪問し終えた時刻。完了時刻
var color, d, f [MAX]int

func dfs_visit(u int) {
	color[u] = GRAY
	time++
	d[u] = time
	//隣接を調べる
	for v := 0; v < n; v++ {
		if M[u][v] == 0 {
			continue
		}
		//隣接するvが、未訪問だった場合
		if color[v] == WHITE {
			dfs_visit(v)
		}
	}
	//訪問完了処理
	color[u] = BLACK
	time++
	f[u] = time
	//訪問完了
}

func dfs() {
	//初期化
	for u := 0; u < n; u++ {
		color[u] = WHITE
	}
	time = 0

	//未訪問のuを始点として、深さ優先探索
	for u := 0; u < n; u++ {

		if color[u] == WHITE {
			dfs_visit(u)
		}
	}

	for u := 0; u < n; u++ {
		fmt.Println(u+1, d[u], f[u])
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 0; i < n; i++ {
		u, k := nextInt(), nextInt()
		M[u-1][u-1] = 0

		//fmt.Println(u, k)
		if k > 0 {
			for j := 0; j < k; j++ {

				v := nextInt()
				M[u-1][v-1] = 1

			}
		}

	}

	dfs()

}

C++: #include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <climits>

#include <vector>
#include <memory>
using namespace std;

#define DEBUG (0)
#define USE_UNIQUE_PTR (0)

#if DEBUG
#define DPRINTF(...) do { \
    printf("D(L%d) %s: ", __LINE__, __func__); \
    printf(__VA_ARGS__); \
  } while (false)
#else
#define DPRINTF(...)
#endif // DEBUG

int g_time = 1;

class Vertex {
public:
  Vertex() :
    id_(-1),
    discover_time_(-1),
    finish_time_(-1),
    adjacentNum_(0),
    adjacentIds_(nullptr),
    isVisited_(false) { }

  ~Vertex() {
#if !USE_UNIQUE_PTR
    if (adjacentIds_)
      delete [] adjacentIds_;
#endif
  }

  void setAdjacency(const vector<int> &adjacentIds);

  inline void setId(int id) { id_ = id; }
  inline void setDiscoverTime(int time) { discover_time_ = time; }
  inline void setFinishTime(int time) { finish_time_ = time; }
  inline void setVisited(bool visited) { isVisited_ = visited; }

  inline int getId() { return id_; }
  inline int getDiscoverTime() { return discover_time_; }
  inline int getFinishTime() { return finish_time_; }
  inline bool getVisited() { return isVisited_; }
  inline int getAdjacentNum() { return adjacentNum_; }
  inline int getAdjacentId(int idx) { return adjacentIds_[idx]; }

  void printTime();
  void printAdj();

private:
  int id_;
  int discover_time_;
  int finish_time_;

  int adjacentNum_;
#if USE_UNIQUE_PTR
  unique_ptr<int[]> adjacentIds_;
#else
  int *adjacentIds_;
#endif // USE_UNIQUE_PTR

  bool isVisited_;
};


void Vertex::setAdjacency(const vector<int> &adjacentIds)
{
  if (adjacentIds_) assert(1);

  adjacentNum_ = adjacentIds.size();
#if USE_UNIQUE_PTR
  adjacentIds_ = unique_ptr<int[]>(new int[adjacentNum_]);
#else
  adjacentIds_ = new int[adjacentNum_];
#endif // USE_UNIQUE_PTR

  for (int i = 0; i < adjacentNum_; i++)
  {
    adjacentIds_[i] = adjacentIds[i];
  }

}

void Vertex::printTime()
{
  printf("%d %d %d\n", id_, discover_time_, finish_time_);
}

void Vertex::printAdj()
{
  DPRINTF("%d %d", id_, adjacentNum_);
  for (int i = 0; i < adjacentNum_; i++) {
    printf(" %d", adjacentIds_[i]);
  }
  cout << endl;
}


void dfs(Vertex vertices[], int idx)
{

  DPRINTF("time %d  idx %d\n", g_time, idx);

  Vertex &vtx = vertices[idx];

  if (!vtx.getVisited())
  {
    vtx.setDiscoverTime(g_time);
    g_time++;
  }

  for (int i = 0; i < vtx.getAdjacentNum(); i++)
  {
    int id = vtx.getAdjacentId(i);
    dfs(vertices, id);
  }

  if (!vtx.getVisited())
  {
    vtx.setFinishTime(g_time);
    vtx.setVisited(true);
    g_time++;
  }

}


int main()
{
  int n;

  cin >> n; cin.ignore();
  DPRINTF("Node num %d\n", n);

  Vertex vertices[n+1];

  for (int i = 1; i <= n; i++)
  {
    int id;
    int num;

    cin >> id >> num;
    vertices[i].setId(id);
    DPRINTF("node %d (num %d)\n", id, num);

    vector<int> adjs;

    for (int j = 0; j < num; j++)
    {
      int adj;
      cin >> adj;

      adjs.push_back(adj);
    }

    if (adjs.size())
      vertices[i].setAdjacency(adjs);

    cin.ignore();
  }

#if DEBUG
  for (int i = 1; i <= n; i++) vertices[i].printAdj();
#endif

  for (int i = 1; i <= n; i++)
    if (!vertices[i].getVisited())
      dfs(vertices, i);

  for (int i = 1; i <= n; i++) vertices[i].printTime();

  return 0;
}

C++: #include <stdio.h>

int time, n;
int d[100], f[100], color[100];
int M[100][100];

void dfs(int u) {
    color[u] = 1;
    d[u] = ++time;
    for (int i=0; i<n; i++) {
        if(M[u][i] && color[i] == 0) {
            dfs(i);
        }
    }
    color[u] = 2;
    f[u] = ++time;
}

void dfs_init(){
    time = 0;
    for (int i=0; i<100; i++) color[i] = 0;
    
    for (int i=0; i<n; i++) {
        if(color[i] == 0) dfs(i);
    }
}

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

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

int a[100][100];
int n,p,q,r;
int T[100],F[100];
int Time = 0;
void dfs(int cur) {
	T[cur] = Time;
	Time += 1;
	for (int dst=0; dst < n; ++dst) {
		if(a[cur][dst] == 1 && T[dst] == -1) {
			dfs(dst);
		}
	}
	F[cur] = Time;
	Time += 1;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> p >> q;
		T[i] = -1;
		for (int j=0; j<q; ++j) {
			cin >> r;
			a[p-1][r-1] = 1;
		}
	}
	dfs(0);
	for (int i=0; i<n; ++i) {
		cout << i+1 << " " << T[i]+1 << " " << F[i]+1 << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<utility>
using namespace std;
vector<int> l[101];
int matrix[100][100];
pair<int,int> t[101];
bool visited[101];
int tim=0;
void dfs(int cur)
{
    tim+=1;
    t[cur].first=tim;
    //cerr<<"visiting "<<cur<<' '<<tim<<endl;
    visited[cur]=true;
    
    for(int i=0;i<l[cur].size();i++)
    {
        if((matrix[cur-1][l[cur][i]-1]==1)&&(visited[i]==false))
        {
            dfs(l[cur][i]);
        }
    }
    
    tim+=1;
    t[cur].second=tim;
    
    
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            int tmp;
            cin>>tmp;
            l[u].push_back(tmp);
        }
    }
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            matrix[i][j]=0;
        }
    }
    for(int i=1;i<n+1;i++)
    {
        visited[i]=false;
        for(int j=0;j<l[i].size();j++)
        {
            matrix[i-1][l[i][j]-1]=1;
        }
    }
    
    for(int i=1;i<n+1;i++)
    {
        if(visited[i]==false)
            dfs(i);
    }
    
    for(int i=1;i<n+1;i++)
    {
        cout<<i<<" "<<t[i].first<<" "<<t[i].second<<endl;
    }
}