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

C++: #define _CRT_SECURE_NO_WARNINGS
#include<cstdio>

bool table[102][102] = {};
int color[102] = {}; //0:?????¢?´¢???1:?¨??????????, 2:??¢?´¢??????
int n, counter = 0;
int t_visit[102] = {};
int t_finish[102] = {};

void DFS(int y) {
	
	for (int j = 0; j <= n - 1;j++) {

		//?¨????or??¢?´¢???????????£???????????????
		if ((table[y][j] == 1)&&(color[j] == 0)) {
			color[y] = 1; //?¨???????????????????
			if (t_visit[y] == 0) t_visit[y] = ++counter;
			DFS(j);
		}

	}

	color[y] = 2; //??¢?´¢???????????????
	if (t_visit[y] == 0) t_visit[y] = ++counter;
	if (t_finish[y] == 0) t_finish[y] = ++counter;
	
}

int main(void) {
	int u, k, s;

	scanf("%d", &n);

	for (int i = 0;i <= n - 1;i++) {
		scanf("%d %d", &u, &k);
		for (int j = 0;j <= k - 1;j++) {
			scanf("%d", &s);
			table[u - 1][s - 1] = 1;
		}
	}


	for (int i = 0;i <= n - 1;i++) {
		if (color[i] == 0) {
			DFS(0);
		}
	}


	for (int i = 0; i <= n - 1;i++) {
		printf("%d %d %d\n", i + 1, t_visit[i], t_finish[i]);
	}

	return 0;
}