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 <stack>
using namespace std;

#define WHITE 0
#define GRAY 1
#define BLACK 2

int main ()
{
    int N;
    cin >> N;

    int M[N][N];
    int D[N], F[N], C[N];

    for (int i = 0; i < N; i++)
    {
        D[i] = 0;
        F[i] = 0;
        C[i] = WHITE;
        
        for (int j = 0; j < N; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < N; i++)
    {
        int u, k;
        cin >> u >> k;
        u--;

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

/*
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (j > 0)
                cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
*/
    stack<int> *S = new stack<int>;

    int time = 0;

    S->push(0);
    C[0] = GRAY;
    D[0] = ++time;

    while (S->size() > 0)
    {
        int u = S->top();
        int v = -1;

        // next 
        for (int i = 0; i < N; i++)
        {
            int flag = M[u][i];

            if (flag == 1)
            {
                if (C[i] == WHITE)
                {
                    v = i;
                    break;
                }
            }
        }

        if (v != -1)
        {
            if (C[v] == WHITE)
            {
            C[v] = GRAY;
            D[v] = ++time;
            S->push(v);
            }
        }
        else
        {
            S->pop();
            C[u] = BLACK;
            F[u] = ++time;
        }
    }

    for (int i = 0; i < N; i++)
    {
        cout << i + 1 << " " << D[i] << " " << F[i] << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;


void solve(int);

typedef struct{
  int k;
  vector<int> ls;
  int f,d;
}node_t;

node_t node[101];
int t=0;

int main(){
  int n;
  int u;

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> u; 
    cin >> node[u].k;
    node[u].ls.resize(node[u].k);
    node[u].d = node[u].f = -1;
    for(int j=0; j<node[u].k; j++){
      cin >> node[u].ls[j];
    }
    sort(node[u].ls.begin() , node[u].ls.end());
  }
 
  for(int i=0; i<n; i++)
    solve(i+1);

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

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % 2019;
    } else {
        return modpow(m, n - 1) * m % 2019;
    }
}
long long n;
vector<bool> visited(100, false);
vector<int> t1(100);
vector<int> t2(100);
vector<vector<long long>> graph(100);
int ts = 1;
void dfs(int cur) {
    visited[cur] = true;
    t1[cur] = ts;
    ts++;
    for (int i = 0; i < graph[cur].size(); i++) {
        if (visited[graph[cur][i]] == false) {
            dfs(graph[cur][i]);
        }
    }
    t2[cur] = ts;
    ts++;
}
signed main() {
    cin >> n;
    for (long long i = 0; i < n; i++) {
        long long s, k;
        cin >> s >> k;
        for (int j = 0; j < k; j++) {
            int l;
            cin >> l;
            graph[s - 1].push_back(l - 1);
        }
    }
    REP(i, n) {
        if (!visited[i]) {
            dfs(i);
        }
    }
    REP(i, n) { cout << i + 1 << " " << t1[i] << " " << t2[i] << endl; }
}

C++: #include<stdio.h>
#include<stdlib.h>
#define N 102
#define white 0
#define gray 1
#define black 2

int n,color[N],d[N],f[N],S[N],top=0,t=0,nt[N],a[N][N];

void push(int x){
  if(top==N){
    printf("Stack overflow!\n");
    exit(2);
  }
  S[++top]=x;
}

int pop(void){
  if(top==0){
    printf("Stack is empty!\n");
    exit(3);
  }
  top--;
  return S[top+1];
}

int next(int u){
  int v;
  for(v=nt[u];v<=n;v++){
    nt[u]=v+1;
    if(a[u][v]) return v;
  }
  return -1;
}

void dfs(int r){
  int i;
  for(i=1;i<=n;i++) nt[i]=0;

  push(r);
  color[r]=gray;
  d[r]=++t;

  while(S[top]!=0){
    int u=S[top],v=next(u);

    if(v!=-1){
    if(color[v]==white){
      color[v]=gray;
      d[v]=++t;
      push(v);
    }
    }
    else {
      pop();
      color[u]=black;
      f[u]=++t;
    }
  }
}

void dfs_init(){
  int i,u;
  for(i=1;i<=n;i++){
    color[i]=white;
  }
  t=0;

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

}

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

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);
  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=1;j<=k;j++){
      scanf("%d",&v);
      a[u][v]=1;
    }
  }

  dfs_init();
  print();


  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int cnt=1;
void depth(vector< vector<int> > &vv,vector<int> &f,vector<int> &c,int num){
	f[num]=cnt;
	cnt++;
	for(int i=0; i<vv[num].size(); i++){
		if(vv[num][i]!=0 && f[i]==0){
			depth(vv,f,c,i);
		}
	}
	if(c[num]==0){
		c[num]=cnt;
		cnt++;
	}
}
int main(){
	int n;
	cin>>n;
	vector< vector<int> > v(n,vector<int> (n,0));
	vector<int> ft(n,0);
	vector<int> ct(n,0);
	int u[n];
	for(int i=0; i<n; i++){
		int k;
		cin>>u[i]>>k;
		for(int j=0; j<k; j++){
			int x;
			cin>>x;
			v[i][x-1]=1;
		}
	}
	for(int i=0; i<n; i++){
		if(ft[i]==0){
			depth(v,ft,ct,i);
		}
	}
	for(int i=0; i<n; i++){
		cout<<u[i]<<" "<<ft[i]<<" "<<ct[i]<<endl;
	}
  return 0;
}

C++:  #include<stdio.h>
#define Gray 0
#define White 1
#define Black 2
int time;
int d[101],f[101],color[101],Adj[101][101];  
int n;

void DFS_Visit(int u){
  int i;  
  color[u]=Gray;
  d[u]=++time;
  for(i=1;i<=n;i++){
    if(color[i]==White && Adj[u][i]==1) DFS_Visit(i);
  }
  color[u]=Black;
  f[u]=++time;
}

void DFS(){
  int i;
  for(i=1;i<=n;i++){
    color[i]=White;
  }
  time=0;
  for(i=1;i<=n;i++){
    if(color[i]==White) DFS_Visit(i);
}
}

main(){
  
  int k,i,j,t,g;

  scanf("%d",&n);
    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	Adj[i][j]=0;
      }
    } 
    
    for(i=1;i<=n;i++){
      scanf("%d",&g);    
      scanf("%d",&k);
      for(j=1;j<=k;j++){
	scanf("%d",&t);
	Adj[g][t]=1;   
      }
    } DFS();
    
    for(i=1;i<=n;i++){
   
      printf("%d %d %d\n",i,d[i],f[i]);
    }
    return 0;
}