//============================================================================
// Name        : NewPartitions1.cpp
// Author      : Us
// Version     : 1.0
// Copyright   : GNU
// Description : DIMENSION 4: Finds partitions of the integral value (9) into (2)
//               (number of edges - number of cycles) positive integers that make the 
//               determinants of the block components of A[#] equal to zero. 
//               Here "#" is the position of the multigraph in the list "lff".
//============================================================================

#include <iostream>
#include <fstream>
#include <stdio.h>
#include <numeric>
#include <cstdlib>
#include <vector>
#include <list>


using namespace std;

static ofstream myfile;

// Please insert in the line below the variables x1,x2

int CalculDet(unsigned short x1,unsigned short x2)
{ 
  return x1*(-2 + x2) - 2*x2;
};

bool validSet(unsigned short * firstNum)

// Please insert in the line below the expression "firstNum[0],.....,firstNum[nv-1]", substituting nv by the difference between the number of edges and the number of cycles of the multigraph

{  if(	0 == CalculDet(firstNum[0],firstNum[1]))
	{      

// Please substitute "?" below by the  difference between the number of edges and the number of cycles

		for( int i = 0; i<2; i++) myfile<< firstNum[i]<<" ";
		myfile<<endl;
	}
	return true;
};

void part(unsigned short k, unsigned short m)
{

     // *** Attention: Partitions with no zeros:

	unsigned short r[k];
	int i,j,s;
       	r[0]=m-k+1;
        for(i=1;i<k;i++){
		r[i]=1;	}
        validSet(r);
	while(r[k-1]!=m-k+1){
		i=k;
		while(r[--i]==1);
		if(i!=k-1){
			r[i]--;
			r[i+1]=2;
			validSet(r);
		}
		else{
			while(r[--i]==1);
			r[i]--;
			s=r[k-1];
			r[k-1]=1;
			r[i+1]=s+1;
			validSet(r);
		}
	}
};


int main()
{

// Please assign the values of the necessary constants: m= dimension of the manifold, z= value of the integral
// nc= number of cycles of the multigraph 

    int m=4 ;
   
    int z=9 ;
   
    int nc=1 ;
   
    
    
    // **** Computes the number of edges

    int cardI =  (m/2+1)*m/4; 
 
    // *** Writes the partitions in the file OutputPart1.txt 
    
    // Please substitute "#" below by the position of the multigraph in the list "lff"
     
     cout << "Writing partitions to the file: OutputPart1.txt"<<endl;
     myfile.open ("OutputPart1.txt");
     part(cardI-nc,z);
     myfile.close();
     cout << "Finished. \n";
     cout << "\n";

     return 0;
}
