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<cstdio>

int G[110][110]={};
int d[110];
int f[110];

int cnt = 0;

void dfs(int i, int n)
{
  int j;

  d[i] = ++cnt;
  for(j = 1;j <= n;j++){
    if(G[i][j] != 1) continue;
    else G[i][j] = 0;
    
    if(d[j] == 0) dfs(j, n);
  }
  f[i] = ++cnt;
}

int main()
{
  int n;
  int i,j;
  int u,k,v;
  
  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d%d", &u, &k);

    for(j = 0;j < k;j++){
      scanf("%d", &v);
      G[u][v] = 1;
    }
  }

  for(i = 1;i <= n;i++)
    if(d[i] == 0) dfs(i, n);

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

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

using namespace std;

int n;
vector<vector<int>> g; 
int time = 0;
vector<int> d, f;
 
void dfs(int node){
    time++;

    if(d[node] == 0){
        d[node] = time;
    }

    for(auto next : g[node]){
        if(d[next] == 0){
            dfs(next);
        }
    }
    
    time++;
    if(f[node] == 0){
        f[node] = time;
    }
    return;
}
    
int main(){
    
    cin >> n;

    d.assign(n + 1, 0);
    f.assign(n + 1, 0);

    g.assign(n + 1, vector<int>());

    for(int i = 0; i < n; i++)
    {
        int nod, numOut;
        cin  >> nod >> numOut;
        for(int j = 0; j < numOut; j++)
        {
            int temp;
            cin >> temp;
            g[nod].push_back(temp);
        }
    }
    
    dfs(1);

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

    return 0;
}

C++: #include <stdio.h>
#include <string.h>
#define N 110
int n;
int m[N][N];
int used[N];
int time = 1;
int start[N];
int end[N];
void dfs(int u){
    used[u] = 1;
    start[u] = time++;
    for(int v = 1; v <= n; v++){
        if(used[v] == 0 && m[u][v]){
            dfs(v);
        }
    }
    end[u] = time++;
}
int main(){
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) m[i][j] = 0;
    for(int i = 0; i < N; i++) used[i] = 0;
    scanf("%d", &n);
    for(int p = 0; p < n; p++){
        int node, k;
        scanf("%d %d", &node, &k);
        for(int i = 0; i < k; i++){
            int b;
            scanf("%d", &b);
            m[node][b] = 1;
        }
    }

    for(int i = 1; i<= n; i++) if(used[i] == 0) dfs(i);
    for(int i = 1; i <= n; i++){
        printf("%d %d %d\n", i, start[i], end[i]);
    }
    return 0;
}

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

#define MAX 100

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

int T;
int N;

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

void dfs(int u)
{
    C[u] = GRAY;
    D[u] = ++T;

    for (int i = 0; i < N; i++)
    {
        if(M[u][i] == 1 && C[i] == WHITE)
        {
            dfs(i);
        }        
    }
    C[u] = BLACK;
    F[u] = ++T;
}

int main ()
{
    cin >> 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;
    }

    T = 0;

    for (int i = 0; i < N; i++)
    {
        if (C[i] == WHITE)
        {
            dfs(i);
        }
    }

    /*
    stack<int> *S = new stack<int>;


    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++)
        {
            if (M[u][i] == 1)
            {
                if (C[i] == WHITE)
                {
                    v = i;
                    break;
                }
            }
        }

        if (v != -1)
        {
            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 <stdio.h>
#define WHITE 0
#define GRAY  1
#define BLACK 2
int color[100];
int d[100],f[100];
int G[100][100];
int n, time = 0;
void dfs(int u)
{
    color[u] = 1;
    d[u] = ++time;
    for (int i = 0; i < n; i++)
    {
        if (G[u][i]==1 && color[i] == 0)
        {
            dfs(i);
        }
    } 
    color[u] = 2;
    f[u] = ++time;
    return;
}
int main()
{
    int k,u,v;
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            G[i][j] = 0; 
        }  
    } 
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d",&u,&k);
        for (int j = 0; j < k; j++)
        {
            scanf("%d",&v);
            G[u-1][v-1] = 1;
        } 
    } 
    for (int i = 0; i < n; i++)
    {
        color[i] = 0; 
        d[i] = 0;
        f[i] = 0;
    } 
    for (int i = 0; i < n; i++)
    {
        if(color[i]==0) dfs(i); 
    } 
    for (int i = 0; i < n; i++)
    {
        printf("%d %d %d\n", i+1, d[i], f[i]); 
    } 
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, t;
vector<int> G[110];
vector<int> d(110), f(110), visited(110, -1); 

void dfs_visit(int u) {
    visited[u] = 0;
    d[u] = ++t;
    for (int v = 0; v < G[u].size(); v++) {
        if (visited[G[u][v]] == -1) {
            dfs_visit(G[u][v]);
        }
    }
    visited[u] = 1;
    f[u] = ++t;
}

void dfs() {
    for (int u = 0; u < n; u++) visited[u] = -1;
    t = 0;
    for (int u = 0; u < n; u++) {
        if (visited[u] == -1) dfs_visit(u);
    }
    for (int u = 0; u < n; u++) {
        cout << u + 1 << " " << d[u] << " " << f[u] << endl;
    }
}

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