Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var depth [101]int
var finish [101]int
var d [101]int
var n, time int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func visit(graph [][]int, u int) {
	depth[u] = 1
	time++
	d[u] = time
	for i := 0; i < n; i++ {
		if graph[u][i] == 1 {
			if depth[i] == 0 {
				visit(graph, i)
			}
		}
	}
	depth[u] = 2
	time++
	finish[u] = time
}
func main() {
	sc.Split(bufio.ScanWords)

	n = nextInt()
	graph := make([][]int, n)
	for i := 0; i < n; i++ {
		graph[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		s := nextInt()
		t := nextInt()
		if t == 0 {
			continue
		}
		for i := 0; i < t; i++ {
			u := nextInt()
			graph[s-1][u-1] = 1
		}
	}
	for i := 0; i < n; i++ {
		if depth[i] == 0 {
			visit(graph, i)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d %d\n", i+1, d[i], finish[i])
	}
}

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

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

struct ver{
    ll d;
    ll f;
};

ll t=0;
vector<vector<ll>> mat;
vector<ver> vers;

void find(ll pos) {
    if(vers[pos].d == 0){
        t++;
        vers[pos].d = t;
    }
    for(ll i:mat[pos]) {
        find(i);
    }
    if(vers[pos].f == 0) {
        t++;
        vers[pos].f = t;
    }
}

int main() {
    ll n;
    cin >> n;
    for(ll i=0;i<n;i++) {
        ll u,k;
        cin>>u>>k;
        vector<ll> aaa;
        for(ll j=0;j<k;j++) {
            ll tmp;
            cin>>tmp;
            aaa.push_back(tmp-1);
        }
        mat.push_back(aaa);
    }
    for(ll i=0;i<n;i++) {
        vers.push_back(ver{0,0});
    }
    find(0);
    for(ll i=0;i<n;i++) {
        cout << i+1<<" "<<vers[i].d<<" "<<vers[i].f<<endl;
    }
}

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

using namespace std;

const int max_v = 100;
vector<vector<int>> adj_list;
int d[max_v] = { 0 };
int f[max_v] = { 0 };
int discovered[max_v] = { 0 };
int time = 1;

// Depth-first Search ( Stack implementation)
void DFS(int v)
{
	stack<int> S;
	S.push(v);
	discovered[v] = 1;
	d[v] = time++;
	int i = 0;
	while (!S.empty()) {
		v = S.top();
		if (i < adj_list[v - 1].size()) {
			int u = adj_list[v - 1][i++];
			if (discovered[u] == 0) {
				discovered[u] = 1;
				d[u] = time++;
				S.push(u);
				i = 0;
			}
		}
		else {
			S.pop();
			f[v] = time++;
			i = 0;
		}
	}
}

int main(int argc, char** argv)
{
	// Input
	int n;
	int u, k;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		int v;
		vector<int> adj;
		for (int j = 0; j < k; j++) {
			cin >> v;
			adj.push_back(v);
		}
		adj_list.push_back(adj);
	}

	// Depth-first Search
	DFS(1);

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

	return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <bitset>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

struct dd{
    int d,f;
    dd(){
        d=0;
        f=0;
    }
};
bool data[101][101]={};
void f1(dd*,int,int&,int);

int main()
{
    int N,M,num1,num2;
    dd ddata[101]={};
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>num1;
        cin>>M;
        for(int j=0;j<M;j++){
            cin>>num2;
            data[num1][num2]=true;
        }
    }
    int time=1;
    for(int i=1;i<=N;i++){
        if(!ddata[i].d)f1(ddata,i,time,N);
    }
    for(int i=1;i<=N;i++){
        cout<<i<<' '<<ddata[i].d;
        if(ddata[i].d){
            cout<<' '<<ddata[i].f;
        }
        cout<<endl;
    }
}
void f1(dd* ddata,int num,int& time,int N)
{
    if(!ddata[num].d)ddata[num].d=time++;
    data[num][num]=false;
    for(int i=1;i<=N;i++){
        if(data[num][i]){
            data[num][i]=false;
            data[i][num]=false;
            f1(ddata,i,time,N);
        }
    }
    if(!ddata[num].f)ddata[num].f=time++;
}