Cod sursa(job #190265)

Utilizator andrei-alphaAndrei-Bogdan Antonescu andrei-alpha Data 21 mai 2008 13:03:23
Problema Triplete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <stdio.h>
#include <algorithm>
using namespace std;

#define Nmax 4000
#define Mmax 60800
#define IN "triplete.in"
#define OUT "triplete.out"

struct mch{short int a,b;};
mch xx[Mmax];
int nr,nrm,n,m;
bool a[Nmax][Nmax];

bool comp(const mch &x, const mch &y)  
{       
    if(x.a<y.a)       
        return true;
	if(x.a==y.a && x.b<y.b)
		return true;
   return false;       
} 

void scan()
{
	
	int x,y;
	freopen(IN, "r",stdin);
	freopen(OUT, "w",stdout);
	
	scanf("%d%d", &n,&m);
	for(int i=1;i<=m;++i)
	{	
		scanf("%d%d", &x,&y);
		xx[++nr].a=x;
		xx[nr].b=y;
		a[x][y]=a[y][x]=1;
	}
}

void solve()
{
	sort(xx+1,xx+n+1, comp); 
	int rez=0;
	
	for(int k=1;k<=m;++k)
	{
		//printf("%d %d\n",xx[k].a,xx[k].b);
		if(xx[k].a==xx[k+1].a && a[xx[k].a][xx[k].b])
		{
			++rez;
			++k;
			//printf("%d %d\n",xx[k].a,xx[k].b);
		}
	}	
	printf("%d", rez);
}

int main()
{
	scan();
	solve();
	return 0;
}