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;

int n;
int v[100][100];
int color[100], d[100], f[100], tt;
/*
  color: ???????????¶???
    0: ???????¨??????????????????????;
    1: ?¨??????????????????????;
    2: ???????????????;
  d: ?????????????????????;
  f: ?????????????????????;
  tt: ?¨??????????;
*/


int dfs(int u)
{
  color[u] = 1;
  d[u] = ++tt; //????????????????¨????
  for (int i = 0; i < n; i++) {
    if (v[u][i] == 0) continue;
    if (color[i] == 0) {
      dfs(i);
    }
  }
  color[u] = 2;
  f[u] = ++tt; //?¨?????????????
}

signed main()
{
  int u, k;

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

  }

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

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

  return (0);
}

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, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

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 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) {
      if (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;
    nt[i] = 0;
  }
  tt = 0;

  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() {

  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }

  int u, k, v;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--; // to 0 origin
    for (int j = 0; j < n; j++) {
      cin >> v;
      v--; // to 0 origin
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

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

enum Status {WHITE, GRAY, BLACK};

stack<int> stc;
Status *status;
int *discovered, *finished;
vector<vector<int> > a;
int n, timer;

void dfs(int i){
        if(status[i]==BLACK) return;
        if(status[i]==WHITE){
                discovered[i] = ++timer;
                status[i] = GRAY;
        }
        stc.push(i);

        for(int j=0;j<a[i].size();j++) dfs(a[i][j]);

        if(status[i]==GRAY){
                finished[i] = ++timer;
                status[i] = BLACK;
        }
        stc.pop();
}

int main(){

        cin>>n;
        a = vector<vector<int> >(n, vector<int>());
        status = new Status[n];
        discovered = new int[n];
        finished = new int[n];

        int m, k, r;
        for(int i=0;i<n;i++){
                cin>>r;
                cin>>m;
                for(int j=0;j<m;j++){
                        cin>>k;
                        a[r-1].emplace_back(k-1);
                }
        }
        for(int i=0;i<n;i++) status[i] = WHITE;

        timer = 0;
        dfs(0);


        for(int i=0;i<n;i++){
                cout<<i+1<<" "<<discovered[i]<<" "<<finished[i]<<endl;
        }
        return 0;
}

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

using namespace std;

class DFS
{
public:
  int n;
  int solve();
  int dfs( int v, int t, vector<vector<int>>& adj, vector<int>& d, vector<int>& f );
};

int DFS::dfs( int v, int t, vector<vector<int>>& adj, vector<int>& d, vector<int>& f )
{
  if ( d[v] )
    return t;
  else
    d[v] = t++;

  for ( auto i = 1; i <= n; ++i )
    if ( adj[v][i] )
      t = dfs( i, t, adj, d, f );

  f[v] = t;

  return ++t;
}

int DFS::solve()
{
  cin >> n;

  vector<vector<int>> adj(n+1, vector<int>(n+1, 0));
  vector<int> d(n+1,0);
  vector<int> f(n+1,0);

  for ( auto i = 0; i < n; ++i )
    {
      int x, k;
      cin >> x;
      cin >> k;
      for ( auto j = 0; j < k; ++j )
        {
          int y;
          cin >> y;
          adj[x][y] = 1;
        }
    }

  int t = 1;
  
  for ( auto i = 1; i <= n; ++i )
    t = dfs( i, t, adj, d, f );

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

int main()
{
  DFS d;

  d.solve();

  return 0;
}

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

void DFS(vector<vector<int> > A, vector<int> &d, vector<int> &f, vector<int> &visit, int &t, int v){
	
	visit[v] = 1;
	d[v] = t++;

	for(int i=0;i<A[v].size();i++)
		if((A[v][i] == 1) && (visit[i] == 0))
			DFS(A, d, f, visit, t, i);

	f[v] = t++;
}

int main(){
	int n, u, k, t=1;
	vector<vector<int> > A;
	vector<int> d, f, visit;

	cin>>n;
	A.resize(n);
	d.resize(n);
	f.resize(n);
	for(int i=0;i<n;i++){
		A[i].resize(n);
		visit.push_back(0);
	}

	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			A[i][j] = 0;

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

	DFS(A, d, f, visit, t, 0);
	for(int i=0;i<n;i++)
		cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;

	return 0;
}

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

int r[101][101];
int d[101], f[101], num, visit[101], p=0;

void dfs(int n){
    if(!visit[n]){
        visit[n]++;
        d[n] = ++p;
        for(int i=1; i<num+1; i++)
            if(r[n][i]) dfs(i);
        f[n] = ++p;
    }
}

int main(void){
    int u, k, v;
    cin >> num;
    for(int i=0; i<num; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v;
            r[u][v]++;
        }
    }
    for(int i=1; i<num+1; i++){
        if(!visit[i]) dfs(i);
    }
    for(int i=1; i<num+1; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
}