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<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

stack<int> S;
int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N]; //未訪問な次の頂点を保持

//未訪問な次の頂点を返す．全て訪問済みなら-1を返す
int next(int u){
    for(int v = nt[u]; v < n; v++){
        nt[u] = v + 1;
        if(M[u][v]) return v;
    }
    return -1;
}

void dfs_visit(int i){
    S.push(i);
    color[i] = GRAY;
    d[i] = ++tt;

    while(!S.empty()){
        int u = S.top();
        int v = next(u);
        if(v != -1){
            if(color[v] == WHITE){
                S.push(v);
                color[v] = GRAY;
                d[v] = ++tt;
            }
        }else{
            color[u] = BLACK;
            f[u] = ++tt;
            S.pop();
        }
    }
}

void dfs(){
    for(int i = 0; i < n; i++){
        color[i] = WHITE;
        nt[i] = 0;
    }
    tt = 0;

    for(int i = 0; i < n; i++){
        if(color[i] == WHITE) dfs_visit(i);
    }

    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--; //0オリジンに変換
        for(int j = 0; j < k; j++){
            cin >> v;
            v--; //0オリジンに変換
            M[u][v] = 1;
        }
    }

    dfs();
    
    return 0;

}

C++: //Shunji Lin 08-144505

#include <iostream>

using namespace std;

bool adjmatrix[101][101]; //adjmatrix
int discover[101];
int processed[101];
int cur_time = 0;


void DFS(int vertex, int N) {
  cur_time++;
  discover[vertex] = cur_time; // set cost
  
  for (int i =1; i<= N; i++) {
    if(adjmatrix[vertex][i] && discover[i] == -1) {
      DFS(i, N);
    }
  }
  
  cur_time++;
  processed[vertex] = cur_time;
}


  
int main() {
  const int cur_time = 0;
  
  for (int i = 0; i < 101; i++) {
    discover[i] = -1; // upper limit
    processed[i] = -1;
  }
  int N;
  cin >> N;

  for (int i = 1; i <= N; i++) {
    int vertex, degree;
    cin >> vertex >> degree;

    for (int j = 0; j < degree; j++) {
      int outvertex;
      cin >> outvertex;
      adjmatrix[i][outvertex] = true;
    }
  }

  
  

  DFS(1,N);


  for (int i = 1; i <=N; i++) {
    if (discover[i] != -1) {
      cout << i << " " << discover[i] << " "<< processed[i] << endl;
    }
  }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define vector_rsort(x) sort(all(x));reverse(all(x))
#define array_rsort(x,n) sort(x,x+n);reverse(x,x+n);
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int n,t=1;
int d[105],f[105];
int used[105];
vi g[105];

void init(){
  rep(i,105){
    d[i]=f[i]=INF;
  }
}

void dfs(int now){
  d[now]=min(d[now],t);
  rep(i,g[now].size()){
    if(!used[g[now][i]]){
      used[g[now][i]]=true;
      t++;
      dfs(g[now][i]);
    }
  }
  t++;
  f[now]=min(f[now],t);
}

int main(){
  int u,k,v;
  cin>>n;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>v;
      g[u].pb(v);
    }
  }
  init();
  dfs(1);
  REP(i,1,n+1){
    cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
  }
  return 0;
}

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

C++: #include <iostream>
#include <stack>

using namespace std;

int color[100];
int d[100];
int f[100];
int G[100][100];
int nt[100];
int n;

int WHITE = 1;
int GRAY = 2;
int BLACK = 3;

int _time = 0;

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(int r) {
  for (int i = 0; i < n; i++) nt[i] = 0;

  stack<int> S;

  S.push(r);
  color[r] = GRAY;
  d[r] = ++_time;

  while(!S.empty()){
    int u = S.top();
    int v = next(u);

    if(v != -1) {
      if(color[v] == WHITE) {
        color[v] = GRAY;
        d[v] = ++_time;

        S.push(v);
      }
    } else {
      S.pop();
      color[u] = BLACK;
      f[u] = ++_time;
    }
  }
}

void dfs_init() {
  for(int i = 0; i < n; i++) {
    color[i] = WHITE;
  }
  _time = 0;

  for(int u = 0; u < n; u++) {
    if (color[u] == WHITE) {
      dfs(u);
    }
  }
}

int main() {
  int m, k, l;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> k;
    cin >> m;

    for (int j = 0; j < m; j++) {
      int l;
      cin >> l;

      G[k-1][l-1] = 1;
    }
  }

  for (int i = 0; i < n; i++) {
    dfs_init();
  }

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