hdu 2094

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 }

转载于:https://www.cnblogs.com/lzsz1212/archive/2012/04/11/2441682.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值