//#include "lapack.h"
#include<math.h>
#include <stdio.h>
#include <stdlib.h>


double conexa(int **m,int k)
{
  int i,j,sum;
  double * A,*W, *WORK;
  long N, LDA, LWORK, INFO;
  double con;
  void nomemo();
  
  A= (double *) malloc (k*k * sizeof(double)); if (A==NULL) nomemo();
  W= (double *) malloc (k * sizeof(double)); if (W==NULL) nomemo();
  WORK= (double *) malloc ((3*k-1) * sizeof(double)); if (WORK==NULL) nomemo();
 
  // Construimos la Laplaciana

  for(i=0;i<k;i++)
    {
      for(j=0;j<k;j++)
	{
	  A[i*k+j]=(double) (-1)*m[i][j];
	}
    }
   for(i=0;i<k;i++)
    {
      sum=0;
      for(j=0;j<k;j++)
	{
	  sum+=m[i][j];
	}
      A[i*k+i]=sum;
    }

 /***** AUTOVALORES Y AUTOVECTORES *****/

  N=k;
  LDA=k;
  LWORK=3*k-1;

  dsyev ("V","U",&N,A,&LDA,W,WORK,&LWORK,&INFO,sizeof(char),sizeof(char)); 

  //  for(i=0;i<50;i++)
  //    {
  //      printf("%f,%e,%g\n",W[i],W[i],W[i]);
  //    }
  
  con=W[1];

  free(A);
  free(W);
  free(WORK);

  return(con);
}
