hdu2094

2586 ワード

 
 

:    , , , flag , , 。    。。。 WA ?    , ==1, Yes。 , - -I。 But。。。 - -I。 eg:A B,B C; :D E、E F、F D。 , A D、E、F , - -III, 。    , ( ) 。                                                              2012-04-13

/*

#include"stdio.h"
#include"string.h"
int main()
{
	int n;
	int i;
	int flag[1111];
	char name[1111][22];
	int k;
	int k1,k2;
	char str1[22],str2[22];
	int d;
	int temp;
	while(scanf("%d",&n),n)
	{
		d=0;
		k=0;
		for(i=0;i<1111;i++)
			flag[i]=i;


		for(i=0;i<n;i++)
		{
			scanf("%s%s",str1,str2);
			for(k1=0;k1<k;k1++)
				if(strcmp(name[k1],str1)==0)
					break;
			if(k1==k)
			{
				strcpy(name[k],str1);
				k++;
			}


			for(k2=0;k2<k;k2++)
				if(strcmp(name[k2],str2)==0)
					break;
			if(k2==k)
			{
				strcpy(name[k],str2);
				k++;
			}


			flag[k2]=flag[k1];
		}


		temp=k;
		while(temp--)
		{
			for(i=0;i<k;i++)
				flag[i]=flag[flag[i]];
		}


		for(i=1;i<k;i++)
			if(flag[i]!=flag[i-1])
			{
				d=1;
				break;
			}


		if(d==1)
			printf("No
"); else printf("Yes
"); } return 0; }

*/
#include"stdio.h"
#include"string.h"
int main()
{
	int flag[1111];
	int name[1111][22];
	int str1[22],str2[22];
	int k1,k2,k;
	int i;
	int n;
	int count;
	while(scanf("%d",&n),n)
	{
		k=0;
		memset(flag,0,sizeof(flag));
		for(i=0;i<n;i++)
		{
			scanf("%s%s",str1,str2);
			for(k1=0;k1<k;k1++)
				if(strcmp(name[k1],str1)==0)
					break;
			if(k1==k)
			{
				strcpy(name[k],str1);
				k++;
			}

			for(k2=0;k2<k;k2++)
				if(strcmp(name[k2],str2)==0)
					break;
			if(k2==k)
			{
				strcpy(name[k],str2);
				k++;
			}

			flag[k2]=1;
		}

		count=0;
		for(i=0;i<k;i++)
			if(flag[i]==0)
				count++;
		if(count==1)
			printf("Yes
"); else printf("No
"); } return 0; }