Pagini recente » Cod sursa (job #1219831) | Cod sursa (job #2050728) | Cod sursa (job #2236095) | Cod sursa (job #471283) | Cod sursa (job #13086)
Cod sursa(job #13086)
using namespace std;
#include<fstream>
#include<stdio.h>
struct nod{int vec;nod* next;};
typedef nod* list;
list a[4100],z[4100];
char viz[4100];
int niv[4100];
int sol=0;
void go(int x,int nv)
{
viz[x]=1;
niv[x]=nv;
list k;
for(k=a[x];k;k=k->next)
if(viz[k->vec]==0)
go(k->vec,nv+1);
else
if(niv[k->vec]==niv[x]-2)
sol++;
}
int main()
{
FILE *fin=fopen("triplete.in","r"),
*fout=fopen("triplete.out","w");
int n,m,i,x,y;
fscanf(fin,"%d%d",&n,&m);
for(i=1;i<=m;i++)
{
fscanf(fin,"%d%d",&x,&y);
if(a[x]==NULL)
a[x]=z[x]=new nod;
else
{
z[x]->next=new nod;
z[x]=z[x]->next;
}
z[x]->vec=y;
z[x]->next=NULL;
if(a[y]==NULL)
a[y]=z[y]=new nod;
else
{
z[y]->next=new nod;
z[y]=z[y]->next;
}
z[y]->vec=x;
z[y]->next=NULL;
}
memset(viz,0,sizeof viz);
go(1,0);
fprintf(fout,"%d\n",sol);
fclose(fin);
fclose(fout);
return 0;
}