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 <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>
#include <stack>
#include <map>

using namespace std;

template<typename ISTREAM>
void readGraphListAsMatrix(const size_t n, ISTREAM& cin, vector< vector<int> >& graphMatrix) {
	graphMatrix = vector< vector<int> >(n, vector<int>(n, 0));
	for (size_t i = 0; i != n; ++i) {
		size_t u;
		size_t k;
		cin >> u >> k;
		for (size_t j = 0; j != k; ++j) {
			size_t v;
			cin >> v;
			graphMatrix.at(u - 1).at(v - 1) = 1;
		}
	}
}

void printMatrix(const vector< vector<int> >& grapthMatrix) {
	const size_t n = grapthMatrix.size();
	for (size_t i = 0; i != n; ++i) {
		const vector<int>& adj = grapthMatrix.at(i);
		cout << adj.front();
		for (size_t j = 1; j != n; ++j) {
			cout << " " << adj.at(j);
		}
		cout << endl;
	}
}


template<typename T>
void execute(T& cin) {
	size_t n;
	cin >> n;
	vector< vector<int> > graphMatrix;
	readGraphListAsMatrix(n, cin, graphMatrix);
	stack<int> visitedNodeIDs;
	visitedNodeIDs.push(1);
	int time = 0;
	vector<pair<int, int>> timeStamp(n,make_pair(0,0));//pair<初回訪問時刻, 完了時刻>
	timeStamp.at(0).first = 1;
	while (!visitedNodeIDs.empty()) {
		++time;
		const int nodeID = visitedNodeIDs.top();
		vector<int>& neighbourNodeList = graphMatrix.at(nodeID - 1);
		vector<int>::iterator result = find(neighbourNodeList.begin(), neighbourNodeList.end(), 1);
		if (result != neighbourNodeList.end()) {
			const int nextVisitID = distance(neighbourNodeList.begin(), result) + 1;
			timeStamp.at(nextVisitID - 1).first = time + 1;
			*result = 0;
			visitedNodeIDs.push(nextVisitID);
		}
		else {
			//隣接リストに検索対象なし
			timeStamp.at(nodeID - 1).second = time+1;
			visitedNodeIDs.pop();
		}
	}
	for (int i = 0; i != n; ++i) {
		cout << i + 1 << " " << timeStamp.at(i).first << " " << timeStamp.at(i).second << endl;
	}
}

int main()
{

	execute(cin);


	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

void dfs(int node, std::vector<std::vector<int>>& v, int& time, std::vector<std::vector<int>>& log) {
    log[node].push_back(++time);
    for (int i=0; i<v[node].size(); i++) {
        if (node != v[node][i] and log[v[node][i]].size() == 0) {
            dfs(v[node][i], v, time, log);
        }
    }
    log[node].push_back(++time);
} 

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, u, k, vi, time=0;
    std::cin >> n;
    std::vector<std::vector<int>> v(n+1), log(n+1);
    for (int i=0; i<n; i++) {
        std::cin >> u >> k;
        for (int j=0; j<k; j++) {
            std::cin >> vi;
            v[u].push_back(vi);
        }
    }
    for (int i=1; i<=n; i++) {
        if (log[i].size() == 0) {
            dfs(i, v, time, log);
        }
    }
    for (int i=1; i<=n; i++) {
        std::cout << i << " " << log[i][0] << " " << log[i][1] << "\n";
    }

    return 0;
}

C++: #define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

vector<int> G[100+1];
vector<int> d(100+1,-1);
vector<int> f(100+1,-1);
int timer= 1;

void dfs(int x){

    if(d[x]!=-1)
        return;
    d[x] = timer;
    timer++;
    for (int i = 0; i < G[x].size(); ++i) {
        dfs(G[x][i]);
    }
    f[x] = timer;
    timer++;
}

int main(void) {

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

    for (int i = 1; i <= n; ++i) {
        dfs(i);
    }

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

    return 0;
}

C++: #include <stdio.h>
int n,G[101][101];
int d[101];
int T = 0;
int F[101] = {0};
int k = 0;

void visit(int u) {
  int i,j,v;
  T++;  
  d[u] = T;

  for(v=0;v<n;v++) {
    if(G[u][v] == 1 && d[v] == 0 ) {
      visit(v);
    }
  }
  
  T++;
  F[u] = T;

}

int main() {
  
  
  int i,j,k,l,u,a,t;

  for(i=0;i<n;i++) d[i] = 0;

  scanf("%d",&n);

  for(i=0;i<n+1;i++)
    for(j=0;j<n+1;j++) {
      G[i][j] = 0;

    }

  for(i=0;i<n;i++){

    scanf("%d %d ",&k,&u);
    //    printf("u = %d\n",u);

    for(j=0;j<u;j++) {
      scanf("%d",&a);
      G[k -1][a-1] = 1;
      // printf("G[%d][%d] = 1\n",i,k-1);
    }
  }
  for(i=0;i<n;i++) {
    if(d[i] == 0) 
    visit (i);
  }
    
  for(i=0;i<n;i++) {
    printf("%d %d %d\n",i+1,d[i],F[i]);
  }
  return 0;

    
    
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
static const int N=100,WHITE=0,GRAY=1,BLACK=2;

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u) {
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for (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() {
  int u;
  for (u=0; u<n; u++) {
    color[u]=WHITE;
  }
  tt=0;
  for (u=0; u<n; u++) {
    if (color[u]==WHITE) {
      dfs_visit(u);
    }
  }
  for (u=0; u<n; u++) {
    cout<<u+1<<" "<<d[u]<<" "<<f[u]<<endl;
  }
}
int main() {
  int u,v,k,i,j;
  cin>>n;
  for (i=0; i<n; i++) {
    for (j=0; j<n; j++) {
      M[i][j]=0;
    }
  }
  for (i=0; i<n; i++) {
    cin>>u>>k;
    u--;
    for (j=0; j<k; j++) {
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  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, tt;
int M[N][N], color[N], d[N], f[N], nt[N]; 

int next(int u){
	for(int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if(M[u][v] == 1) 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 {
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


void dfs() {
	for(int i = 0; i < n; i++) {
	     color[i] = WHITE;
	}
	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() {
	int n, k , u, v;
	cin >> n;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}
	cin >> u >> k;
	u--;
	for(int i = 0; i < k; i++) {
	    cin >> v;
	    v--;
		M[u][v] = 1; 
	}
	dfs();
	return 0;
}