Cod sursa(job #1465910)

Utilizator StefanMudragMudrag Stefan StefanMudrag Data 28 iulie 2015 11:40:50
Problema Triplete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include<iostream>
#include<fstream>
#define MMAX 129
#define NMAX 4097
#define MAX 65537

using namespace std;
ifstream fin("triplete.in");
ofstream fout("triplete.out");
struct muchie {int a, b;};
muchie st[MAX];
long  A[NMAX][MMAX];
int n,m,nr;
void read()
{   fin>>n>>m;
   nr=n/32;
   int x,y;
   for(int i=1;i<=m;i++)
   {
       fin>>x>>y;
       st[i].a=x;st[i].b=y;
       A[x][y/32]=A[x][y/32]|(1<<((y%32)));
       A[y][x/32]=A[y][x/32]|(1<<((x%32)));

   }
   fin.close();
}
int numar(int c)
{
    int x=0;

    while(c)
    {  c=c&(c-1);

        x++;}

    return x;



}
void solve()
{  int x,y,sol=0;
   long c;

    for(int j=1;j<=m;j++)
       {  x=st[j].a;y=st[j].b;
      for(int i=0;i<=nr;i++)
      {
             c=A[x][i]&A[y][i];

             sol+=numar(c);

      }
        A[x][y/32]=A[x][y/32]&(255-(1<<(y%32)));
        A[y][x/32]=A[y][x/32]&(255-((1<<(x%32))));
      }

fout<<sol;
}

int main()
{
    read();

     solve();

    return 0;
}