Cod sursa(job #30280)

Utilizator snaked31Stanica Andrei snaked31 Data 13 martie 2007 18:24:02
Problema Triplete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <stdio.h>
#include <vector>

using namespace std;

#define nm 4100
#define base 32

vector <int> vx, vy;
unsigned int a[nm][nm/base];
int n, m, i, x, y, j;
long long sol;

void read()

{
	scanf("%d %d", &n, &m);

    for (i=1; i<=m; i++)
    {
        scanf("%d %d", &x, &y);

        vx.push_back(x);
        vy.push_back(y);
        a[x][(y)/base] |= ((unsigned int)1 << (y-1) % base);
        a[y][(x)/base] |= ((unsigned int)1 << (x-1) % base);
    }
}



void solve()

{
	sol = 0;

    for (i=0; i<m; ++i)
    {
/*        for (j=1; j<=n; ++j)
        {
        	if (a[vx[i]][j] == 1 && a[vy[i]][j] == 1)
            {
                ++sol;
            }
        }*/
        for (j=0; j<=(n/base)+1; ++j)
        {
        	x = a[vx[i]][j] & a[vy[i]][j];
            while (x != 0)
            {
            	if (x % 2 == 1)
                	++ sol;
                x /= 2;
            }
        }
    }
    sol /= 3;
}


void write()

{
	printf("%lld\n", sol);
}


int main()

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

    read();
    solve();
    write();

    fclose(stdin);
    fclose(stdout);

	return 0;
}