I cannot understand the meaning of the question .... in general: It starts from a specified room... can I return to room 0... and close all the doors in the figure .. the door cannot be opened after being closed...
The input is amazing. I read a row in gets and then process it...
Abstract some more... open the door as an edge .. so it is equivalent to finding a path .. to facilitate all sides .. and each side is traversed only once... there are two cases .. one is to start from 0 .. after finishing all the edges, return to 0... this is a typical Euler loop... the other is starting from other points .. reached 0 .. and finish all the edges ..
Determine whether an image can have Euler's loop .. is to see if the degrees of all vertices are even... because all vertices must enter the number of times and the number of times they will go out... it's just a path rather than a loop .. then the start point and the end point must be an odd number of degrees .. the degrees of other points must be an even number...
Program:
#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<math.h>#include<map>#include<queue>#include<stack>#define ll long long#define oo 1000000000#define pi acos(-1)using namespace std; int m,n,ans,a[105];char s[505];int main(){ int p,len,i,k; while (~scanf("%s",s)) { if (s[0]!='S') break; scanf("%d%d",&m,&n); gets(s); memset(a,0,sizeof(a)); ans=0; for (p=0;p<n;p++) { gets(s); len=strlen(s); i=0; while (i<len) { k=0; while (s[i]>='0' && s[i]<='9') { k=k*10+s[i]-'0'; i++; } if (k) { a[p]++; a[k]++; ans++; k=0; } i++; } } gets(s); k=0; for (i=0;i<n;i++) if (a[i]%2) k++; if (!m) { if (!k) printf("YES %d\n",ans); else printf("NO\n"); }else { if (k==2 && a[m]%2 && a[0]%2) printf("YES %d\n",ans); else printf("NO\n"); } } return 0;}