hdu 2094

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2094

题意:题目说的不清楚,有很多情况都没说到。不过数据很水,只要判断入度为0的点是否只有1个就可以了。

代码:

 1 # include <stdio.h>
 2 # include <string.h>
 3 
 4 
 5 int cnt ;
 6 char tab[2010][100] ;
 7 int degree[2010] ;
 8 
 9 
10 int find(char a[])
11 {
12     int i ;
13     for (i = 0 ; i < cnt ; i++)
14         if (strcmp(a, tab[i])==0) return i ;
15     strcpy (tab[cnt], a) ;
16     return cnt++ ;
17 }
18 
19 
20 int main ()
21 {
22     int aa, bb, ans, i, n ;
23     char a[100], b[100] ;
24     while (~scanf ("%d", &n),n)
25     {
26         cnt = 0 ;
27         memset (degree, 0, sizeof(degree)) ;
28         for (i = 0 ; i < n ; i++)
29         {
30             scanf ("%s %s", a, b) ;
31             aa = find(a) ;
32             bb = find(b) ;
33             degree[bb]++ ;
34         }
35         ans = 0 ;
36         for (i = 0 ;i  < cnt ; i++)
37             if (degree[i] == 0) ans++ ;
38         if (ans != 1) puts ("No") ;
39         else puts ("Yes") ;
40     }
41     return 0 ;
42 }
posted @ 2012-04-11 04:24  Seraph2012  阅读(243)  评论(0编辑  收藏  举报