Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	g := make([][]int, n+1)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
		}
	}

	d := make([]int, n+1)
	f := make([]int, n+1)
	dfs(&g, &d, &f, 1, 1)

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d %d\n", i, d[i], f[i])
	}
}

func dfs(g *[][]int, d *[]int, f *[]int, id int, t int) int {
	if (*d)[id] > 0 {
		return t
	}
	(*d)[id] = t
	t += 1
	for i := 0; i < len((*g)[id]); i++ {
		t = dfs(g, d, f, (*g)[id][i], t)
	}
	(*f)[id] = t
	return t+1
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

using Graph = vector<vector<int>>;

vector<bool> seen;
vector<int> first_order;
vector<int> last_order;

void dfs(const Graph &G, int v, int& ptr){
  first_order[v] = ptr++;

  seen[v] = true;
  for(int nv : G[v]){
    if(seen[nv] == true) continue;
    dfs(G, nv, ptr);
  }

  last_order[v] = ptr++;
}

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

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

  seen.assign(n+1, false);
  first_order.resize(n+1);
  last_order.resize(n+1);
  int ptr = 1;
  REP(i, 1, n){
    if(seen[i] == false){
      dfs(G, i, ptr);
    }
  }

  REP(i, 1, n){
    printf("%d %d %d\n", i, first_order[i], last_order[i]);
  }

  return 0;
}

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

int n;
int common_time = 1;

int adj_matrix[101][101] = {0};
int time_table[101][2] = {0};

void dfs(int node)
{
    if (time_table[node][0] == 0)
    {
        time_table[node][0] = common_time;
        common_time++;
    }
    else
    {
        return;
    }

    for (int i = 1; i <= n; i++)
    {
        if (adj_matrix[node][i] == 1)
        {
            dfs(i);
        }
    }

    time_table[node][1] = common_time;
    common_time++;
}

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;
            adj_matrix[u][v] = 1;
        }
    }

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

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

    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <stack>
#include <string>
using namespace std;

#define NUM 100
int node_num;
int V[NUM + 1][NUM + 1];
int d[NUM + 1];
int f[NUM + 1];
string color[NUM + 1];
int t;
int pos;
stack<int> s;

void createAdj(int n){
    for(int i = 1; i < NUM; i++){
        for(int j = 1; j < NUM; j++){
            V[i][j] = 0;
        }
    }

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

        int n;
        scanf("%d", &n);

        int num2;
        for(int j = 0; j < n; j++){
            scanf("%d", &num2);
            V[num1][num2] = 1;
        }
    }
}

int search(int n){
    for(int i = 1; i <= node_num; i++) {
        if(V[n][i] == 1 && color[i] == "white")
            return i;
    }
    return -1;
}

void dfs_init(){
    t = 0;
    for(int i = 0; i < NUM; i++){
        color[i] = "white";
    }
}

void dfs(){
    s.push(1);
    pos = 1;
    t++;
    color[1] = "grey";
    f[1] = t;

    while(s.size()){
        int u = s.top();
        int next_node = search(u);
        if(next_node != -1){
            pos = next_node;
            s.push(next_node);
            pos = next_node;
            t++;
            color[next_node] = "grey";
            d[next_node] = t;
        }else{
            s.pop();
            color[u] = "black";
            t++;
            f[u] = t;
        }
    }
}

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

int main(void){
    scanf("%d", &node_num);
    createAdj(node_num);

    dfs_init();
    dfs();

    print();
}

C++: #include <iostream>
#include <stack>
using namespace std;
const int MAX_N = 100;

int A[MAX_N+1][MAX_N+1];
pair<int, int> TIMESTAMPS[MAX_N+1];
int N;

void solve() {
  int ts = 0;
  stack<int> S;
  S.push(1);

  while (!S.empty()) {
    int c = S.top();

    if (TIMESTAMPS[c].first == 0)
      TIMESTAMPS[c].first = ++ts;

    for (int i = N; i > 0; i--) {
      if (A[c][i] == 1 && TIMESTAMPS[i].second == 0)
        S.push(i);
    }

    if (S.top() == c) {
      if (TIMESTAMPS[c].second == 0)
        TIMESTAMPS[c].second = ++ts;
      S.pop();
    }
  }
}

int main() {
  cin >> N;

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      A[i][j] = 0;

    }
    TIMESTAMPS[i] = make_pair(0, 0);
  }

  for (int i = 0; i < N; i++) {
    int u, k; cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int t; cin >> t;
      A[u][t] = 1;
    }
  }

  solve();

  for (int i = 1; i <= N; i++) {
    cout << i << ' '
         << TIMESTAMPS[i].first << ' '
         << TIMESTAMPS[i].second << endl;
  }

  return 0;
}

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

using namespace std;

struct Node {
    int visit = 0;
    vector<int> next;
    int s = 0;
    int start = 0;
    int end = 0;
};

int main() {
    int n, id, k, temp, time = 1;
    Node node[101];
    stack<int> st;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        for (int j = 0; j < k; j++) {
            cin >> temp;
            node[id].next.push_back(temp);
        }
    }

    while (1) {
        int s = -1;
        for (int i = 1; i <= n; i++) {
            if (node[i].visit == 0) {
                s = i;
                break;
            }
        }
        if (s == -1) {
            break;
        }
        
        node[s].start = time++;
        node[s].visit = 1;
        st.push(s);
        while (!st.empty()) {
            temp = st.top();
            if (node[temp].s < node[temp].next.size()) {
                if (node[node[temp].next[node[temp].s]].visit == 0) {
                    node[node[temp].next[node[temp].s]].start = time++;
                    node[node[temp].next[node[temp].s]].visit = 1;
                    st.push(node[temp].next[node[temp].s++]);
                }
                else {
                    node[temp].s++;
                }
            }
            else {
                node[temp].visit = 2;
                node[temp].end = time++;
                st.pop();
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " " << node[i].start << " " << node[i].end << endl;
    }

    return 0;
}

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;
}