Cod sursa(job #22393)

Utilizator portocalaDiculescu Elena Alexandra portocala Data 26 februarie 2007 13:09:45
Problema Triplete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <fstream.h>
//#include <time.h>
#define max(x,y) ((x)>(y) ? (x):(y))
unsigned long mat[10][4],mask,t,y;
unsigned int v[36][2],m,n;
int main()
{ifstream f("triplete.in");
ofstream g("triplete.out");
unsigned int i,j,k,x,n1,n2;
//clock_t start,end;
//start=clock();
f>>n>>m;
for(i=1;i<=m;i++)
 {f>>v[i][0]>>v[i][1];
  mat[v[i][0]-1][(v[i][1]-1)/32]+=1<<((v[i][1]-1)%32);
  mat[v[i][1]-1][(v[i][0]-1)/32]+=1<<((v[i][0]-1)%32);
 }
f.close();
n1=n/32;
n2=n%32;
for(i=1;i<=m;i++)
 {x=max(v[i][0],v[i][1]);
  j=x/32;
  y=mat[v[i][0]-1][j]&mat[v[i][1]-1][j];
  x=x%32;
  if(y)
  {if(n1){ mask=1<<(x);
	   for(k=(x);k<32;k++)
	    {if(mask&y)t++;
	      mask=mask<<1;
	     }
	   for(x=j+1;x<=n1;x++)
	    {mask=1;
	     y=mat[v[i][0]-1][x]&mat[v[i][1]-1][x];
	     for(k=0;k<32;k++)
	      {if(mask&y)t++;
		mask=mask<<1;
	      }
	    }
	  }
   else {mask=1<<(x);
	 for(k=(x);k<=n2;k++)
	  {if(mask&y)t++;
	    mask=mask<<1;
	   }
	}
  }
 }
g<<t<<'\n';
g.close();
//end=clock();
//cout<<((end-start)*1000)/CLK_TCK;
return 0;
}