Cod sursa(job #133066)

Utilizator gabitzish1Gabriel Bitis gabitzish1 Data 7 februarie 2008 13:51:14
Problema Triplete Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <stdio.h>

int n, m;
long long contor;
typedef struct
{
	int x, y;
} muchie;
muchie a[66000];

typedef struct nod
{
	int x;
	nod *a;
} *pNod;
pNod v[5000];

void citire()
{
	freopen("triplete.in","r",stdin);
	freopen("triplete.out","w",stdout);
	pNod p;
	int i;
	scanf("%d %d",&n, &m);
	for (i = 1; i <= m; i++)
	{
		scanf("%d %d", &a[i].x, &a[i].y);
		p = new nod;
		p -> x = a[i].x;
		p -> a = v[a[i].y];
		v[a[i].y] = p;
	    p = new nod;
		p -> x = a[i].y;
		p -> a = v[a[i].x];
		v[a[i].x] = p;
	}
}

int main()
{
	citire();
	int i;
	pNod p, q;
	for (i = 1; i <= m; i++)
	{
		for (p = v[a[i].x]; p != NULL; p = p -> a)
			for (q = v[a[i].y]; q != NULL; q = q -> a)
				if (p -> x == q -> x && p -> x != a[i].x && p -> x != a[i].y) contor++;
	}
	contor /= 3;

	printf("%lld\n",contor);
	return 0;
}