Pagini recente » Cod sursa (job #2121513) | Cod sursa (job #2303599) | Cod sursa (job #1859410) | Cod sursa (job #1314511) | Cod sursa (job #8454)
Cod sursa(job #8454)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct list
{
int nod;
struct list *urm;
};
int n,m,i,j,x,h[4097];
struct list *v[4097];
int main()
{
freopen("triplete.in","r",stdin);
freopen("triplete.out","w",stdout);
scanf("%d %d",&n,&m);
for (int k=1;k<=n;k++) v[k]=NULL;
for (int k=0;k<m;k++)
{
scanf("%d %d",&i,&j);
if (i>j) x=i,i=j,j=x;
struct list *p;
p=(struct list*) malloc(sizeof(struct list));
p->urm=v[i];
p->nod=j;
v[i]=p;
}
x=0;
for (int i=1;i<=n;i++)
{
memset(h,0,sizeof(h));
struct list *p;
p=v[i];
while (p!=NULL) h[p->nod]=1,p=p->urm;
p=v[i];
while (p!=NULL)
{
struct list *q;
q=v[p->nod];
while (q!=NULL)
{
if (h[q->nod]==1) x++;
q=q->urm;
}
p=p->urm;
}
}
printf("%d\n",x);
fclose(stdout);
return 0;
}