boolean RemoveCycles(ArrayList<Integer> a){
		int current = a.get(a.size()-1);
		int last = a.get(a.size()-1);
		if(a.size() > 1){
			last = a.get(a.size()-2);
		}
	  	for(int i = 0; i < n; i++){
	  		if(i != current && i != last && grid[current][i] >= 0){ // look for link
  				if(a.contains(i)){ // arraylist has a cycle
  					boolean found = false;
  					int max = 0;
  					int maxi = -1;
  					int maxj = -1;
  					int lasti = current;
  					System.out.print("Found cycle: ");
  					for(Integer j : a){
  						if(!found && j != i) continue;
  						found = true;
  						System.out.print(j+" ");
  						if(grid[j][lasti] > max){
  							max = grid[j][lasti];
  							maxi = lasti;
  							maxj = j;
  						}
  						lasti = j;
  					}
  					System.out.println();
  					System.out.println("Removing edge " + maxi + " " + maxj + " " + max);
  					System.out.println();
  					grid[maxi][maxj] = -1;
  					grid[maxj][maxi] = -1;
  					return true;
  				}
  				else{ // no cycle, recurse
	  				a.add(i);
	  				if(RemoveCycles(a)){
	  					return true;
	  				}
	  				a.remove(a.size()-1);
	  			}
	  		}
	  	}
	  	return false;
	}