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++: // C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int ll
#define loop(__x, __start, __end) for(Int __x = __start; __x < __end; __x++)
#define loopdown(__x, __start, __end) for(Int __x = __start; __x > __end; __x--)
#define rep(__n) for(Int __x = 0; __x < __n; __x++)
#define span(__a,__x,__y) __a.begin()+__x,__a.begin()+__y
#define span_all(__a) __a.begin(),__a.end()
#define len(__x) (__x.size())
#define last(__x) (__x[__x.size()-1])

using namespace std;

struct Point {
  Int x, y;
  Point(Int x, Int y): x(x), y(y) {}
  Point(): x(0), y(0) {}

  bool operator< (const Point &p1) const {
    return x < p1.x && y < p1.y;
  }
};
ostream & operator << (ostream & out, Point const & v) {
  out << "Point(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Point & v) {
  Int x, y;
  in >> x; in >> y; v.x = x; v.y = y;
  return in;
}

// Geometry

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

Int N, t = 1;
vector<vector<Int> > G(101);
vector<Int> D(101, -1), F(101, -1);

void input() {
  cin >> N;
  Int v, c, u;
  rep(N) {
    cin >> v >> c; v--;
    rep(c) {
      cin >> u; u--;
      G.at(v).push_back(u);
    }
  }
}

void dfs(Int n) {
  if (D.at(n) >= 0) return;
  D.at(n) = t++;
  for (auto v: G.at(n)) {
    dfs(v);
  }
  F.at(n) = t++;
  return;
}

void solve() {
  for (int i=0; i<N; i++) dfs(i);
  for (int i=0; i<N; i++) {
    cout << (i+1) << " " << D.at(i) << " " << F.at(i) << endl;
  }
}

int main() {
  input();
  solve();
  return 0;
}

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

int DFS(vector<vector<int> >& G,
        vector<pair<int, int> >& rec, int i, int t) {
    rec[i].first = t;
    for (int j = 1; j <= G[i].size(); j++) {
        if (G[i][j] && rec[j].first == -1) {
            t = DFS(G, rec, j, t + 1);
        }
    }
    rec[i].second = t + 1;
    return rec[i].second;
}

int main(){
    int n;
    cin >> n;
    vector<vector<int> > G(n + 1, vector<int>(n + 1, 0));
    for (int i = 1; i <= n; i++) {
        int num, k;
        cin >> num >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            G[i][v] = 1;
        }
    }
    vector<pair<int, int> > record(n + 1, make_pair(-1, -1));
    DFS(G, record, 1, 1);

    for (int i = 1; i <= n; i++) {
        cout << i << " " << record[i].first
                  << " " << record[i].second << endl;
    }

    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;
vector<int> v[101];
int d[101] = {0};
int f[101] = {0};
int t = 0;
void dfs(int id) {
    //d mark
    d[id] = t;
    t++;
    for(int adj: v[id]) {
        if(d[adj] == 0) {
            dfs(adj);
            t++;
        }
    }
    f[id] = t;
}

int main() {
    int n;
    cin >> n;
    for(int i=1; i<=n; i++) {
        int u, k;
        cin >> u >> k;
        for(int j=0; j<k; j++) {
            int adj;
            cin >> adj;
            v[i].push_back(adj);
        }
    }
    for(int i=1; i<=n; i++) {
        if(d[i] == 0) {
            t++;
            dfs(i);
        }
    }

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

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

using Graph = vector<vector<int>>;

int dfs(Graph &graph, vector<int> &d, vector<int> &f, int cur, int time)
{
    if(d[cur] > 0) return time;
    d[cur] = time;
    time++;
    for(int child : graph[cur])
    {
        time = dfs(graph, d, f, child, time);
    }
    f[cur] = time;
    time++;
    return time;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    Graph graph(n);
    REP(i, n) 
    {
        int u, k;
        cin >> u >> k;
        REP(j, k) 
        {
            int v;
            cin >> v;
            graph[u-1].push_back(v-1);
        }
    }

    vector<int> d(n, 0), f(n, 0);
    int time = 1;
    REP(i, n)
    {
        if(d[i] > 0) continue;
        time = dfs(graph, d, f, i, time);
    }

    REP(i, n)
    {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}