Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nVerts := scanInt(sc)
	graph := make([][]int, nVerts+1)

	for i := 0; i < nVerts; i++ {
		u := scanInt(sc)
		nDegrees := scanInt(sc)

		graph[u] = make([]int, nDegrees)
		for d := 0; d < nDegrees; d++ {
			graph[u][d] = scanInt(sc)
		}
	}

	starts := make([]int, nVerts+1)
	ends := make([]int, nVerts+1)
	time := 1

	var dfs func(u int)
	dfs = func(u int) {
		if starts[u] > 0 {
			return
		}

		starts[u] = time
		time += 1

		for _, v := range graph[u] {
			dfs(v)
		}

		ends[u] = time
		time += 1
	}

	for i := 1; i <= nVerts; i++ {
		dfs(i)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= nVerts; i++ {
		fmt.Fprintf(w, "%d %d %d\n", i, starts[i], ends[i])
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

using namespace std;

struct Node {
    bool visit = false;
    vector<int> next;
    int position = 0;
    int start;
    int end;
};

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

    node[1].start = time++;
    st.push(1);
    while (!st.empty()) {
        temp = st.top();
        if (node[temp].position < node[temp].next.size() && node[node[temp].next[node[temp].position]].visit == false) {
            node[node[temp].next[node[temp].position]].start = time++;
            st.push(node[temp].next[node[temp].position++]);
        }
        else {
            node[temp].visit = true;
            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<iostream>
#define N 101
using namespace std;

int n,d[N][N],m[N],f[N],s[N],ti;
void dfs(int t){
  ti++,m[t]+=ti,s[t]=1;
  for(int i=1;i<=n;i++) if(d[t][i]==1 && s[i]==0)dfs(i);
  ti++,f[t]+=ti;
}

int main(){
  int nx,s,fst;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>fst>>nx;
    for(int j=0;j<nx;j++){
      cin>>s;
      d[fst][s]=1;
    }
  }
  dfs(1);
  for(int i=1;i<=n;i++) cout<<i<<" "<<m[i]<<" "<<f[i]<<endl;
  
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja

using Graph = vector<vector<int>>;
vector<bool> seen;
int STS[105];
int EDS[105];
int s = 0;

static void dfs(const Graph &G, int v) {
    seen[v] = true;

    STS[v] = ++s;
    
    for (auto t : G[v]) {
        if (seen[t]) continue;
        dfs(G, t);
    }

    EDS[v] = ++s;
}

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

    seen.assign(n, false);

    for (int i = 1; i <= n; i++) {
        if (!seen[i]) {
            dfs(G, i);
        }
    }


    REP(i, n) {
        cout << i+1 << " " << STS[i+1] << " " << EDS[i+1] << "\n";
    }

    return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, tt;
int M[N][N], color[N], d[N], f[N], nt[N]; 

void dfs_visit(int r) {
    for(int i = 0; i < n; i++) {
        nt[i] = 0;
	}
	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;
	while(!S.empty()) {
		int u = S.top();
		int v = 0;
		for(v = 0; v < n; v++) {
			if(M[u][v] == 0) continue;
			if(color[v] != WHITE) continue;
			break; 
		}
		if(v != n) {
			if(color[v] == WHITE) {
			   color[v] = GRAY;
			   d[v] = ++tt;
			   S.push(v); 	
			}
		} else if(v == n){
		   color[u] = BLACK;
		   S.pop();
		   f[u] = ++tt;
		}
	} 
}


void dfs() {
	for(int i = 0; i < n; i++) {
	     color[i] = WHITE;
	}
	tt = 0;
		
	for(int u = 0; u < n; u++) {
		if(color[u]) dfs_visit(u);
	}

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

int main() {
	int k , u, v;
	cin >> n;
	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++) {
		cin >> u >> k;
	    u--;
	    for(int i = 0; i < k; i++) {
	        cin >> v;
	        v--;
		   M[u][v] = 1; 
     	}
	} 
	
	dfs();
	
	return 0;
}

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

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

using namespace std;


int adjacencyList[MAX + 1][MAX + 1];
int color[MAX + 1];
int d[MAX + 1];
int f[MAX + 1];
int n;



int minWhiteNode(int v)
{

	for (int i = 1; i <= n; i++) {
		if (color[i] == WHITE && adjacencyList[v][i] == 1 && i != v) {
			return i;
		}
	}
	return 	MAX + 1;
}


void dfs()
{
	stack<int> S;
	int cr;
	int timer = 1;

	S.push(1);
	color[1] = GRAY;
	d[1] = 1;

	while (S.size() > 0) 
	{
		cr = minWhiteNode(S.top());
		timer++;

		if (cr != MAX + 1) {
			S.push(cr);
			color[cr] = GRAY;
			d[cr] = timer;
		}
		else {
			int poped = S.top();
			S.pop();
			color[poped] = BLACK;
			f[poped] = timer;
		}
	}
}

int main(void)
{

	int u;
	int k;
	int v;


	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> u >> k;

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

	}

	dfs();

	for (int i = 1; i <= n; i++) {
		cout << i << " " <<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;
    }
}