Cod sursa(job #1542484)

Utilizator SilviuIIon Silviu SilviuI Data 5 decembrie 2015 13:46:52
Problema Triplete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <stdio.h>
#include <vector>
#include <algorithm>
#define bit 25
#define nmax 66000
using namespace std;
struct date { int x,y; };
int i,j,n,m,b,sol,x,y,uhash[4100][170];
date t[nmax];
int nrbits(int x)
{
    int nr=0;
    while (x>0) {
        nr++; x=x&(x-1);
    }
    return nr;
}
int main() {
freopen("triplete.in","r",stdin);
freopen("triplete.out","w",stdout);
scanf("%d %d",&n,&m);
for (i=1;i<=m;i++) {
    scanf("%d %d",&t[i].x,&t[i].y);
    if (t[i].x>t[i].y) swap(t[i].x,t[i].y);
    if (t[i].y%bit==0) x=t[i].y/bit; else
        x=t[i].y/bit+1;
    y=t[i].y-bit*(x-1);
    uhash[t[i].x][x]=uhash[t[i].x][x]+(1<<(y-1));
}
for (i=1;i<=m;i++) {
    x=t[i].x; y=t[i].y;
    for (j=1;j<=168;j++) {
        b=uhash[x][j]&uhash[y][j];
        sol=sol+nrbits(b);
    }
}
printf("%d",sol);
return 0;
}