Go: #include <bits/stdc++.h>
using namespace std;
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;
static const int N     = 100;

int n, tt;
vector<vector<int>> M(N, vector<int>(N));
vector<int> color(N), d(N), f(N);

void dfs_visit(int u) {
  color[u] = GRAY;
  d[u]     = ++tt;
  for (int 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() {
  tt = 0;

  for (int u = 0; u < n; u++) {
    if (color[u] == WHITE) dfs_visit(u);
  }
  for (int u = 0; u < n; u++) {
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}

int main() {
  int u, v, k;
  cin >> n;
  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 <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_num = -1;
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) {
    if (adjacentIds_ == nullptr || idx > adjacentNum_)
      return -1;
    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);

  assert(idx <= g_num);

  Vertex &vtx = vertices[0];

  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();
  cin >> g_num; cin.ignore();
  DPRINTF("Node num %d\n", g_num);

  Vertex vertices[g_num+1];

  for (int i = 1; i <= g_num; 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 <= g_num; i++) vertices[i].printAdj();
#endif

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

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

  return 0;
}

C++: #include <queue>
#include <map>
#include <cstdio>
#include <algorithm>
using namespace std;
map<int,vector<int> >a;
map<int,int>m;
vector<pair<int,pair<int,int> > >v;
int T;
void D(int k){
	m[k]=1;
	int t=T;
	for(int i=0;i<a[k].size();i++)if(!m[a[k][i]])++T,D(a[k][i]);
	T++;
	v.push_back(make_pair(k,make_pair(t,T)));
}
main(){
	int i,j,k,n;
	for(scanf("%d",&n);n--;)for(scanf("%d%d",&i,&k);k--;a[i].push_back(j))scanf("%d",&j);
	D(T=1);
	sort(v.begin(),v.end());
	for(i=0;i<v.size();i++)printf("%d %d %d\n",v[i].first,v[i].second.first,v[i].second.second);
}

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;
//?????\??????
int M[N][N];
//???°??????¶????????¢????
int color[N];
//??\???¶?????????°???¶???
int d[N];
//??\???¶????????????¶???
int f[N];
//???¶???
int tt;
 
int nt[N];
 
//????????????????????????u?????????v
int next(int u){
    for(int v=0;v<n;v++){
        nt[u]=v+1;
        if(M[u][v]&&color[v]==WHITE)
            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&&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;
    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();
}