3 Alice Bob Smith John Alice Smith 5 a c c d d e b e a d 0
Yes No
#include<stdio.h>
#include<map>
#include<string>
#include<iostream>
using namespace std;
const int N = 2005;
void init(int n)
{
map<string,int>mapt;
string sname;
int a,b,in[N]={0},m=0;
while(n--)
{
cin>>sname;
if(mapt[sname]==0)
{
m++; mapt[sname]=m;
}
cin>>sname;
if(mapt[sname]==0)
{
m++; b=m; mapt[sname]=m;
}
else b=mapt[sname];
in[b]++;
}
int k=0;
for(int i=1;i<=m;i++)
if(in[i]==0)
k++;
printf("%s\n",k==1?"Yes":"No");
}
int main()
{
int n;
while(scanf("%d",&n)>0&&n)
{
init(n);
}
}
原文地址:http://blog.csdn.net/u010372095/article/details/45174991