我在雨中飞燕的论坛里看到这个了
有个人在哭,他的这个错在哪,是邮递员那道题,不知道那人知道错哪了没
#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>
#define N 10000
struct Draw
{
int ke;
int data;
Draw* next; //
};
int Sun(Draw* MN,int begin,int end)
{
int sn=0;
int MX[N+1]={0};
int* head,*yet,*zhong;
Draw *p;
zhong=head=yet=MX;
*yet=begin;
while(*head)
{
p=MN+*head-1;
while(p&&(int)p!=0xcdcdcdcd)
{
if(end==p->data)
return sn;
else if(!MN[p->data-1].ke)
{
++yet;
*yet=p->data;
MN[p->data-1].ke=1;
}
p=p->next;
}
if(head==zhong)
{
sn+=1;
zhong=yet;
}
head++;
}
return -1;
}
void Pi(Draw* MN,int i,int j)
{
if(0!=MN[i-1].data)
{
Draw* p,*q=MN[i-1].next;
p=new Draw;
p->ke=0;
p->data=j;
MN[i-1].next=p;
p->next=q;
}
else
MN[i-1].data=j;
}
void Delete(Draw* MN,int n)
{
int i;
Draw* p,*q;
for(i=0;i<n;i++)
{
p=MN[i].next;
while(p&&(int)p!=0xcdcdcdcd)
{
q=p;
p=p->next;
delete q;
}
}
delete[] MN;
}
int main(void)
{
int n,k,i,j,p;
Draw* MN;
while(scanf("%d%d",&n,&k)&&n&&k)
{
MN=new Draw[n];
for(p=0;p<n;p++)
{
MN[p].ke=0;
MN[p].data=0;
}
for(p=0;p<k;p++)
{
scanf("%d%d",&i,&j);
Pi(MN,i,j);
Pi(MN,j,i);
}
scanf("%d%d",&i,&j);
p=Sun(MN,i,j);
if(p>=0)
printf("%d\n",p);
else
printf("No solution\n");
Delete(MN,n);
}
return 0;
}