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;
vector<vector<int>> G;
int N;
vector<int> d;
vector<int> f;
int de = 0;
void dfs(int v,int p){
    d[v] = ++de;
    for(auto nv:G[v]){
        if(d[nv]!=-1) continue;
        dfs(nv,v);
    }
    f[v] = ++de;
}
signed main(){
    stack<int> st;
    cin >> N;
    G.resize(N);
    d.assign(N,-1);
    f.assign(N,-1);
    for(int i=0;i<N;i++){
        int id;cin >> id;
        int k;cin >> k;
        for(int j=0;j<k;j++){
            int a;cin >> a;a--;
            G[i].push_back(a);
        }
    }
    /*st.push(0);
    int dep=0;
    while(!st.empty()){
        int now = st.top();
        dep++;
        d[now] = dep;
        st.pop();
        for(int nv:G[now]){
            if(d[nv]!=-1) continue;
            st.push(nv);
        }
    }*/
    for(int i=0;i<N;i++){
        if(d[i]==-1) dfs(i,-1);
    }
    for(int i=0;i<N;i++){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
int t = 0;

void visit(int u, int *color, int *d, int *f, vector<vector<int>> Adj){
    int zero = 0;
    color[u] = GRAY;
    d[u] = ++t;
    for (int i = 1; i <= Adj[u].size(); i++){
        if (Adj[u][i] == 0){
            break;
        }
        if (color[Adj[u][i]] == WHITE){
            visit(Adj[u][i], color, d, f, Adj);
        }
    }
    color[u] = BLACK;
    f[u] = ++t;
}

int main(int argc, char* argv[]) {
    int n, u, k, v;
    cin >> n;
    n++;
    int color[n], d[n], f[n];
    vector<vector<int>> Adj(n, vector<int>(n, 0));

    for (int i = 1; i <= n; i++) color[i] = WHITE;

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

    for (int i = 1; i < n; i++)
        if (color[i] == WHITE)
            visit(i, color, d, f, Adj);

    for (int i = 1; i < n; i++){
        printf("%d %d %d\n", i, d[i], f[i]);
    }
    return 0;
}

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

int timex = 0;

int n;

string *color = new string[n];

int *d = new int[n];

int *f = new int[n];

int c[100][100];

void dfs(int u){
  color[u] = "glay";
  d[u] = ++timex;

  for(int v = 0; v < n; v++){
    if(c[u][v] == 1 && color[v] == "white"){
      dfs(v);
    }
  }

color[u] = "black";
f[u] = ++timex;

}

int main(){

  int n;

  cin >> n;

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

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

  for(int i = 0; i < n; i++){
    color[i] = "white";
  }

  dfs(0);

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




  return 0;
}

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

using namespace std;

int t;
int N;
int d[110], f[110];
vector<vector<int> > adj(110);
void dfs(int cur){
    d[cur] = t;
    t += 1;
    //cerr << "visiting " << cur << " " << t << endl;
    for(int i = 0; i < adj[cur].size(); ++i){
        int dst = adj[cur][i];
        if(d[dst] == 0){
            dfs(dst);
        }
    }
    f[cur] = t;
    t++;
}

int main(){
    cin >> N;
    t = 1;
    int u, k;
    for(int i = 0; i < N; ++i){
        d[i] = 0;
        f[i] = 0;
    }
    for(int i = 0; i < N; ++i){
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            int v;
            cin >> v;
            adj[u].push_back(v);
        }
        sort(adj[u].begin(), adj[u].end());
    }
    for(int i = 1; i < N+1; ++i){
        if(d[i] == 0) dfs(i);
    }
    
    for(int i = 1; i < N+1; ++i){
        cout << 1 << " " << d[i] << " " << f[i] << endl;
    }
}

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

int a[100][100];
int n,p,q,r;
int T[100],F[100];
int Time = 0;
void dfs(int cur) {
	T[cur] = Time;
	Time += 1;
	for (int dst=0; dst < n; ++dst) {
		if(a[cur][dst] == 1 && T[dst] == -1) {
			dfs(dst);
		}
	}
	F[cur] = Time;
	Time += 1;
}

int main() {
	cin >> n;
	for (int i=0; i<n; ++i) {
		cin >> p >> q;
		T[i] = -1;
		for (int j=0; j<q; ++j) {
			cin >> r;
			a[p-1][r-1] = 1;
		}
	}
	dfs(0);
	for (int i=0; i<n-1; ++i) {
		cout << i+1 << " " << T[i]+1 << " " << F[i]+1 << endl;
	}
	cout << n << " " << T[n-1]+1 << " " << F[n-1]+1 << endl;
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<int> E[101];
bool visited[101];
int in[101];
int out[101];
int count=0;
int nv(int n)
{
	int i=1;
	for(i=1;i<=n;i++)
	{
		if ( visited[i]==false )
			return i;
	}
	if (i>n) return 0;
}

void bfs(int n)
{
	visited[n]=true;
	in[n]=++count;
	for(vector<int>::iterator it=E[n].begin();it!=E[n].end();++it)
	{
		int now=*it;
		if(visited[now]==false)
			bfs(now);
	}
	out[n]=++count;
}

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int e,n0;
		cin>>e>>n0;
		for(int j=0;j<n0;j++)
		{
			int t;
			cin>>t;
			E[e].push_back(t);
		}
		visited[i]=false;
		in[i]=out[i]=0;
	}

	int now=nv(n);
	while(now!=0)
	{
		bfs(now);
		now=nv(n);
	}


/*	for(int i=1;i<=n;i++)
	{
		for(vector<int>::iterator it=E[i].begin();it!=E[i].end();++it)
			cout<<*it<<" ";
		cout<<endl;
	}
*/
	for(int i=1;i<=n;i++)
		cout<<i<<" "<<in[i]<<" "<<out[i]<<endl;
	return 0;

	

}

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

int n, t;
int v[100][100];
int d[100], f[100], r[100];

void stamp(int id) {
	if (d[id - 1] == 0) {
		d[id - 1] = t;
		t++;
		int i = 0;
		while (v[id - 1][i] == 0)
			i++;
		if (i < n && d[i] == 0)
			stamp(i + 1);
		else
			stamp(id);
	}
	else if (f[id - 1] == 0) {
		int i;
		for(i = 0; i < n; i++)
			if (v[id - 1][i] == 1 && d[i] == 0)
				stamp(i + 1);
		if (i > n - 1 && f[id - 1] == 0) {
			f[id - 1] = t;
			t++;
			int j1, ct = 0;
			for (int j = n - 1; j > -1; j--)
				if (v[j][id - 1] == 1 && f[j] == 0 && d[j] != 0) {
					j1 = j;
					ct++;
				}
			if (ct == 1)
				stamp(j1 + 1);
			else {
				for (int j = 1; j < n; j++)
					if (d[j] == d[id - 1] - 1)
						stamp(j + 1);
			}

			int k = 0;
			while (d[k] != 0)
				k++;
			if (k < n)
				stamp(k + 1);
		}
	}
	else	
		return;
}

int main()
{
	cin >> n;

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

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

	for (int i = 0; i < n; i++) {
		int u, k, s;

		cin >> u >> k;

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

	t = 1;
	stamp(1);

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

	return 0;
}