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<iostream>
#include<vector>

using namespace std;

class Node{
private:
 unsigned long nodeId;
 unsigned long timestampStart;
 unsigned long timestampFinish;
 vector<unsigned long> adjectNode;
public:
 Node()
       : timestampStart(0),
         timestampFinish(0){

  cin >> nodeId;
  unsigned long adjectNodeNum = 0;
  cin >> adjectNodeNum;

  adjectNode.assign(adjectNodeNum, 0);
 
  for(unsigned long adjectNode_i = 0; adjectNode_i < adjectNodeNum; ++adjectNode_i){
   cin >> adjectNode[adjectNode_i];
  }

 };

 bool isStampStart(){
  if(timestampStart == 0) return false;
  return true;
 };

 void stampStart(const unsigned long time){
  timestampStart = time;
 };

 void stampFinish(const unsigned long time){
  timestampFinish = time;
 };

 unsigned long getAdjectNodeNum(){
  return adjectNode.size();
 };

 unsigned long getAdjectNode(unsigned  long adjectNode_i){
  return adjectNode[adjectNode_i]-1;

 };

 void display(){
  cout << nodeId          << " ";
  cout << timestampStart  << " ";
  cout << timestampFinish << endl;
 };

protected:

};

class Graph{
private:
 vector<Node*> graph;

 void DepthFirstSearch(Node* node, unsigned long &time){
  ++time;
  node->stampStart(time);
  for(unsigned long adjectNode_i = 0, adjectNodeMax = node->getAdjectNodeNum(); adjectNode_i < adjectNodeMax; ++adjectNode_i){
   unsigned long nextNode = node->getAdjectNode(adjectNode_i);
   if(!graph[nextNode]->isStampStart()) DepthFirstSearch(graph[nextNode], time);

  }
  ++time;
  node->stampFinish(time);

 };
public:
 Graph(unsigned long nodeNum = 0)
       : graph(vector<Node*>(nodeNum, 0)){

   for(unsigned long node_i = 0; node_i < nodeNum; ++node_i){
    graph[node_i] = new Node();
   }

  };

 void DepthFirstSearch(){
  unsigned long time = 0;
  for(unsigned long node_i = 0, nodeMax = graph.size(); node_i < nodeMax; ++node_i){
   if(!graph[node_i]->isStampStart()) DepthFirstSearch(graph[node_i], time);
  }
  
 };

 void display(){
  for(unsigned long node_i = 0, numMax = graph.size(); node_i < numMax; ++node_i){
   graph[node_i]->display();
  }
 };
protected:

};


int main(){

 unsigned long nodeNum = 0; cin >> nodeNum;

 Graph graph(nodeNum);
 graph.DepthFirstSearch();
 graph.display();

 return 0;
};

C++: #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


int visitTime = 1;
int d[101]={},f[101]={},n[101],v[101][101],id;


void dfs(int cur) { // cur????¨????
	d[cur] = visitTime;// cur????¨??????????????¨????
	visitTime += 1;
	rep(i,n[cur]){ // ??¨????????? v[cur][i] ????????????
		if(d[v[cur][i]]==0){ // v[cur][i] ???????¨??????????
			dfs(v[cur][i]);
		}
	}
	f[cur] = visitTime;// cur ????¨????????????????????¨????
	visitTime += 1;
	// ??¢??°??????????????§???????????? (?????¢??°)
}

int main(void){
	int N;
	cin>>N;
	rep(i,N){
		cin>>id;
		cin>>n[id];
		rep(j,n[id])cin>>v[id][j];
	}
	reg(i,1,N){
		if(d[i]==0){
			dfs(i);
		}
	}
	reg(i,1,N)cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

bool adj[105][105] = {0};
int in[105];
int out[105];

int cnt = 1;

void dfs(int now){
    in[now] = cnt++;
    for(int i = 1; i<=100; i++){
        if(adj[now][i] && !in[i])
            dfs(i);
    }
    out[now] = cnt++;    
}


int main(){

    int n = 0;
    scanf("%d", &n);

    for(int i = 1; i<=n; i++){
        int v, c;
        scanf("%d %d", &v, &c);

        while(c--){
            int w = 0;
            scanf("%d", &w);
            adj[v][w] = true;
        }
    }
    
    dfs(1);
    
    for(int i = 1; i<=n; i++){
        printf("%d %d %d\n", i, in[i], out[i]);
    }

    //system("PAUSE");
    return 0;

}

C++: #include<bits/stdc++.h>
using namespace std;

int n,u,k,v;
int g[102][102];
int d[102],f[102];
int sn[102];
int cnt=1;

void dfs(int x);

int main(){
  memset(d,0,sizeof(d));
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>u>>k;
    sn[i]=0;
    for(int j=1;j<=k;j++){
      cin>>v;
      g[u][v]=1;
    }
  }
  
  dfs(1);

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

  return(0);
}

void dfs(int x){
  
  sn[x]=1;
  d[x]=cnt;
  cnt++;
  
  for(int i=1;i<=n;i++){
    if(g[x][i]==1 && sn[i]==0){
      dfs(i);
    }
  }

  f[x]=cnt;
  cnt++;

}

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

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int MAX = 103;
int G[MAX][MAX];
int color[MAX];
int nt[MAX], d[MAX], f[MAX];
int tt, n;

int next(int u) {
  for (int v=nt[u]; v<n; v++) {
    nt[u] = v + 1;
    if (G[u][v]) return v;
  }
  return -1;
}

void dfs_visit(int r) {
  memset(nt, 0, sizeof(nt));
  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() {
  memset(color, WHITE, sizeof(color));
  memset(nt, 0, sizeof(nt));
  tt = 0;

  rep(u,n) {
    if (color[u] == WHITE) dfs_visit(u);
  }
  rep(i,n) {
    cout << i+1 << ' ' << d[i] << ' ' << f[i] << endl;
  }
}

int main() {

  cin >> n;
  rep(i,n) memset(G[i], WHITE, sizeof(G[i])); // init
  int u, k;
  rep(i,n) {
    cin >> u >> k;
    rep(j,k) {
      int t;
      cin >> t;
      G[i][t-1] = 1;
    }
  }

  dfs();

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

vector<vector<int>> g;
vector<int> f,d;
vector<bool> seen;
int tim = 1;

void dfs(int now){
  seen[now] = true;
  d[now] = tim;
  tim++;
  
  for(int next: g[now]){
    if(seen[next]){
      continue;
    }
    dfs(next);
  }
  f[now] = tim;
  tim++;
}

int main(){
  int n;
  cin >> n;
  g = vector<vector<int>>(n);
  f = d = vector<int>(n);
  seen = vector<bool>(n,false);

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

  for (int i = 0; i < n; i++)
  {
    if(!seen[i]) dfs(i);
  }
  for (int i = 0; i < n; i++)
  {
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }  
}