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>

typedef long long ll;

#define rep(i,n) for(int i = 0;i < n;i++);
#define reps(i,l,n) for(int i = l;i <= n;i++);

using namespace std;

int c = 0;
vector<vector<int>> ver(100,vector<int>(100));

void dfs(int target,int *endo,int *d,int *f){
    if(endo[target]) return ;
    endo[target] = 1;
    d[target] = ++c;
    if(ver[target].empty()) {
        f[target] = ++c;
        return ;
    }
    for(auto num : ver[target]){
        dfs(num,endo,d,f);
    }
    f[target] = ++c;
}

int main(){
    int n;
    cin >> n;
    int d[n],v[n],endo[n];
    for(int i=0;i<n;i++){
        d[i] = v[i] = endo[i] = 0;
        int num,hand;
        cin >> num >> hand;
        num--;
        for(int j=0;j<hand;j++){
            int child;
            cin >> child;
            child--;
            ver[num].emplace_back(child);
        }
    }
    for(int i=0;i<n;i++) dfs(i,endo,d,v);
    for(int i=1;i<=n;i++){
        cout << i <<  " " << d[i-1] << " " << v[i-1] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int> > G;
int d[111],f[111],u[111];
void dfs(int v,int& p){
  if(u[v]) return;
  u[v]=1;
  sort(G[v].begin(),G[v].end());
  d[v]=++p;
  for(int u:G[v]) dfs(u,p);
  f[v]=++p;
}
signed main(){
  int n;
  cin>>n;
  G.resize(n,vector<int>());
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      c--;
      G[u].push_back(c);
    }
  }
  int p=0;
  for(int i=0;i<n;i++)
    if(!u[i]) dfs(i,p);
  for(int i=0;i<n;i++) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;;
  return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int v[101][101];
int k[101];
int d[101],f[101];
int n=0;
int u=0;
int t = 0;
void dfs(int l) {
	//cout << "l==" << l << endl;
	if (!d[l]) {
		d[l] = ++t;
	}
	for (int i = 0; i <= n; i++) {
		if (!d[v[l][i]]) {
			dfs(v[l][i]);
		}
	}
	f[l] = ++t;
}
int main(void) {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u;
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> v[u][j];
		}
	}
	for (int i = 0; i < n; i++) {
		f[i] = -1;
	}
	for (int i = 0; i < n; i++) {
		if (!d[i]) {
			dfs(i);
		}
	}

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

	return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const int DONE = 1;
const int YET = 0;
int fin(vector<int>a) {
	rep(i, 0, a.size()) {
		if (a[i] == YET)return i;
	}
	return -1;
}
signed main() {
	int n; cin >> n; vector<vector<int> >vec(n, vector<int>());
	rep(i, 0, n) {
		int u, k; cin >> u >> k;
		u--;
		rep(j, 0, k) {
			int v; cin >> v; v--;
			vec[u].push_back(v);
		}
	}
	vector<int>check(n, 0);
	vector<pair<int, int> >stamp(n);
	stack<int>S;
	S.push(0);
	int t = 1;
	start:
	while (!S.empty()) {
		int u = S.top();
		if (check[u] == YET) {
			stamp[u].first = t++;
			check[u] = DONE;
		}
	here:
		if (DBG) {
			cout << "t == " << t << endl;
			rep(x, 0, n) {
				cout << x + 1 << " " << stamp[x].first << " " << stamp[x].second << endl;
			}
		}
		rep(i, 0, vec[u].size()) {
			if (check[vec[u][i]] == YET) {
				S.push(vec[u][i]);
				check[vec[u][i]] = DONE;
				stamp[vec[u][i]].first = t++;
				u = vec[u][i];
				goto here;
			}
		}
		u = S.top(); S.pop();
		stamp[u].second = t++;
	}
	if (fin(check) != -1) {
		S.push(fin(check));
		goto start;
	}
	rep(i, 0, n) {
		cout << i + 1 << " " << stamp[i].first << " " << stamp[i].second << endl;;
	}

	return 0;
}

C++: #include <cstdio>

typedef struct vertex_{
    int found;
    int d;
    int f;
}vertex;

int search(vertex *array, int (*A)[101], int id, int n, int time){
    if(array[id].found)return time;
    array[id].found=1;
    array[id].d=++time;
    for(int i=1;i<=n;i++){
        if(A[id][i])time=search(array,A,i,n,time);
    }
    array[id].f=++time;
    return time;
}

int searchAll(vertex *array, int (*A)[101], int n){
    int time = 0;
    for(int id=1;id<=n;id++)if(!array[id].found)time=search(array,A,id,n,time);
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    vertex array[n+1];
    for(i=1;i<=n;i++)array[i].found=0;
    int A[101][101];
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            A[i][j]=0;
        }
    }
    for(i=1;i<=n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            A[u][v]=1;
        }
    }
    int time = searchAll(array, A, n);
    for(i=1;i<=n;i++)printf("%d %d %d\n",i,array[i].d,array[i].f);
    return 0;
}

C++: #include <iostream>
using namespace std;
int n,g[150][150],c[100],f[100],e[100],cnt=1;
void dfs(int now){
  c[now]=1;
  f[now]=cnt;
  cnt++;
	for(int i=0;i<n;i++){
		if(g[now][i] && c[i]!=1){
      		dfs(i);
      		cnt++;
		}
    }
  e[now]=cnt;
}
int main(){
 
  int a,k,num;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a>>k;
    for(int j=0;j<k;j++){
      cin>>num;
      g[a-1][num-1]=1;
    }
  }
	for(int i=0;i<n;i++){
	   if(c[i]!=1){
     	 dfs(i);
      	 cnt++;
       }
	}
 
	for(int i=0;i<n;i++){
		cout<<i+1<<" "<<f[i]<<" "<<e[i]<<endl;
	}
  return 0;
 
}

C++: #include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

int g[101][101],n,d[101],f[101];

int main() {
    cin >> n;
    for(int i = 0;i < n;i++) {
        int u,k,v;
        cin >> u >> k;
        for(int j = 0;j < k;j++) {
            cin >> v;
            g[u][v]++;
            g[v][u]++;
        }
    }
    stack<int> dfs;
    int time = 1;
    dfs.push(1);
    d[1] = time;
    while(!dfs.empty()){
        int u = dfs.top();
        bool flag = false;
        for(int i = 1;i <= n;i++){
            if(g[u][i] && d[i] == 0) {
                dfs.push(i);
                time++;
                d[i] = time;
                flag = true;
            }
        }
        if(!flag){
            dfs.pop();
            time++;
            f[u] = time;
        }
    }
    for(int i = 1;i <=n;i++) {
        cout << i << " " << d[i] << " " << f[i] <<endl;
    }
}