Cod sursa(job #8048)

Utilizator love_for_uSpancioc Riana love_for_u Data 23 ianuarie 2007 19:17:41
Problema Triplete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb

#include <stdio.h>
#define NMAX 4096
#define MMAX 66000
#define B 64
#define P 6

struct per { int x, y; } V[MMAX];

long long A[NMAX][NMAX/B];
int i, j, N, M, a, b;
long long rez;

inline void set(int cnf,int x)
{
   A[cnf][x>>P] |= 1 << (x & (B-1));
}

inline int bit_p(long long b, int poz)
{
     if (b & 1<<poz) return 1;

     return 0;
}

int afla_1(long long x)
{
     int i, s = 0;

     for (i = 0; i < B; i++)
       if (bit_p(x, i)) s++;

     return s;
}

int main()
{
     freopen("triplete.in","r",stdin);
     freopen("triplete.out","w",stdout);

     scanf("%d %d", &N, &M);

     if (N == 1) { printf("0\n"); return 0; }
     if (N == 2) { printf("0\n"); return 0; }
     if (N == 3 && M != 3) { printf("0\n"); return 0;}

     rez = 0;

     for (i = 1; i <= M; i++)
     {
          scanf("%d %d", &a, &b);

          V[i].x = a;
          V[i].y = b;

          set(a, b);
          set(b, a);
     }

     for (i = 1; i <= M; i++)
     {
          a = V[i].x;
          b = V[i].y;

          for (j = 0; j <= N/B; j++) rez += afla_1(A[a][j] & A[b][j]);
     }

     printf("%lld\n", rez/3);

     return 0;
}