zoj 1395 Door Man 欧拉回路
#include<stdio.h>
#include<string.h>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int read(char *s)
{
int len;
for(len=0;(s[len]=getchar())!='\n'&&s[len]!=EOF;len++)
;
s[len]=0;
return len;
}
int main()
{
int i,j,n,m,f,cnt[100],sum;
char buf[128];
while(read(buf))
{
if(strcmp(buf,"ENDOFINPUT")==0) break;
sscanf(buf,"%*s %d %d",&m,&n);
memset(cnt,0,sizeof(cnt));
sum=0;
for(i=0;i<n;i++)
{
read(buf);
int k=0;
while(sscanf(buf+k,"%d",&j)==1)
{
sum++;
cnt[i]++;
cnt[j]++;
while(buf[k]&&buf[k]==' ') k++;
while(buf[k]&&buf[k]!=' ') k++;
}
}
read(buf);
int odd=0,even=0;
for(i=0;i<n;i++)
{
if(cnt[i]%2==0) even++;
else odd++;
}
f=0;
if(even==n&&m==0)
{
f=1;
}
else if(odd>2) f=0;
else
{
if(cnt[0]%2==1&&cnt[m]%2==1&&m!=0) f=1;
else f=0;
}
if(f) printf("YES %d\n",sum);
else printf("NO\n");
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/