Go: package main

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

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}

C++: #include <bits/stdc++.h>

using namespace std;
int graph[125][125], color[125], times, s[125], f[125], v, w, n;
class DFS{
public:
	static void search(){
		for(int i = 1;i<=n;i++){
			color[i] = 0;
		}
		times = 0;
		for(int u = 1;u<=n;u++){
			if(color[u] == 0){
				visit(u);
			}
		}
	}
	static void visit(int u){
		color[u] = 1;
		s[u] = ++times;
		for(int w=1;w<=n;w++){
			if(graph[u][w] == 0) continue;
			if(color[w] == 0){
				visit(w);
			}
		}
		color[u] = 2;
		f[u] = ++times;
	}
};
int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			graph[i][j] = 0;
		}
	}

	for(int i=1;i<=n;i++){
		int num;
		int k;
		int tmp;
		cin >> num >> k;
		if(k !=0){
			for(int j=0;j<k;j++){
				cin >> tmp;
				graph[num][tmp] = 1;
			}
		}
	}
	DFS::search();
	int i;
	for(i=1;i<=n;i++){
		cout << i << " " << s[i] << " " << f[i] << endl;
	}
}

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

using namespace std;

int main(){
    stack<int> st;
    int n;
    cin >> n;
    int d[n] = {};
    int f[n] = {};
    int vnum[n][2] = {};
    bool vflag[n] = {};
    int tmp2;
    int num;
    vector<vector<int>> vertex;
    vector<int> tmp;
    for(int i=0;i<n;i++){
        cin >> num;
        cin >> num;
        vnum[i][0] = num;
        for(int j=0;j<num;j++){
            cin >> tmp2;
            tmp.push_back(tmp2);
        }
        vertex.push_back(tmp);
        tmp.clear();
    }
    int cnt = 1;
    bool check;
    int s;
    st.push(0);
    do{
        s = st.top();

        if(((vnum[s][0]==0) && d[s]==0) || (s==vertex[s][vnum[s][1]]-1)){
            vflag[s] = true;
            d[s] = cnt++;
            f[s] = cnt++;
            st.pop();
        }else if(vnum[s][0]==vnum[s][1]){
            vflag[s] = true;
            f[s] = cnt++;
            st.pop();
        }else if((vflag[vertex[s][vnum[s][1]]-1]) && (d[s]==0)){
            if(vnum[s][0]-vnum[s][1]==1){
                vflag[s] = true;
                d[s] = cnt++;
                f[s] = cnt++;
                st.pop();
            }else{
                vnum[s][1]++;
            }
        }else if(vflag[vertex[s][vnum[s][1]]-1]){
            vflag[s] = true;
            f[s] = cnt++;
            st.pop();
        }else if(vflag[s]){
            st.push(vertex[s][vnum[s][1]++] - 1);
        }else{
            if(d[s]==0){
                d[s] = cnt++;
            }
            st.push(vertex[s][vnum[s][1]++] - 1);
            if(vnum[s][0]==vnum[s][1]){
                vflag[s] = true;
            }
            if(vflag[vertex[s][vnum[s][1]]-1]){
                f[s] = cnt++;
                st.pop();
            }
        }
        check = !st.empty();
        if(!check){
            for(int i=0;i<n;i++){
                if(vflag[i]==false){
                    check = true;
                    st.push(i);
                    break;
                }
            }
        }
    }while(check);

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

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

int n;
int M[100][100];
int color[100], d[100], f[100];
int t;

void Dfs(int u) {
  color[u] = 1;
  d[u] = ++t;
  for (int v = 0; v < n; v++) if (M[u][v] && color[v] == 0) Dfs(v);
  color[u] = 2;
  f[u] = ++t;
}

int main() {
  cin >> n;

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

  Dfs(0);

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

  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<vector<int> > v(n);
	vector<int> k(n);
	int x;
	rep(i,n){
		cin>>x;
		cin>>k[i];
		v[i].resize(k[i]);
		rep(j,k[i]){
			cin>>v[i][j];
			v[i][j]--;
		}
	}
	vector<int> a(n),b(n);
	stack<int> s;
	int count=1;
	s.push(0);
	a[0]=1;
	while(s.empty()==0){
		count++;
		int x=s.top();
		rep(i,k[x]){
			if(a[v[x][i]]==0){
				s.push(v[x][i]);
				a[v[x][i]]=count;
				break;
			}
			if(i==k[x]-1){
				k[x]=0;
			}
		}
		if(k[x]==0){
				b[x]=count;
				s.pop();
		}
		if(s.empty()==1){
			rep(i,n){
				if(a[i]==0){
					s.push(i);
					count++;
					a[i]=count;
				}
			}
		}
	}

	rep(i,n){
		cout<<i+1<<" "<<a[i]<<" "<<b[i]<<endl;;
	}

		



	return 0;
}

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

const int MAX_N = 100;
const int WHITE = -1;
const int GRAY = -2;
const int BLACK = -3;

int n;
int color[MAX_N];
bool adj[MAX_N][MAX_N];
int d[MAX_N], f[MAX_N];

int t;

void dfs(int u) {
    color[u] = GRAY;
    d[u] = ++t;
    for (int v = 0; v < n; v++) {
        if (adj[u][v] && color[v] == WHITE) {
            dfs(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++t;
}

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

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            adj[i][j] = false;
        }
    }
    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[u-1][v-1] = true;
        }
    }

    dfs_init();

    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;

vector<int>tree[120];
int c[120], d[120],f[120];
int N,t=0;

void dfs_visit(int u){
  c[u]=1;
  t++;
  d[u]=t;
  for (auto p : tree[u]) {
    if(c[p]==0) dfs_visit(p);
  }
  c[u]=2;
  t++;
  f[u]=t;

}


void dfs(){

  for(int u=0;u<N;u++) c[u]=0;
  for(int u=0;u<N;u++){
    if(c[u]==0) dfs_visit(u);
  }

}

int main() {

  cin >>N;

  //vector<vector<int>> data(N, vector<int>(N));

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

	dfs();

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