编程介的小学生 2017-06-06 16:41 采纳率: 20.5%
浏览 1093
已采纳

God and Devil

Problem Description
There are many gods and devils living on HDU Island, and echo is one of them. Gods always tell the truth whereas devils sometimes tell the truth but sometimes not. What's more, every god and devil knows all the others are a god or a devil.
One day, an accident unfortunately happened which made echo lose her memory. She was so despairing and determined to turn to others for help. She asked all the residents a question, but all of the answers were merely "Be careful! X is a devil!". As a result she failed to arouse her memory. However, she has to find out a method to calculate the minimum number of devils on the island. Could you help echo to manage it well?

Input
There are multi-cases (The total number of cases won't exceed 20). First line is an integer N(1<=N<=15000), the total number of gods and devils. Then N lines follow, each line includes a name, and the length of each name won't exceed 30. The first name is "echo". The next N-1 lines will be as the formation "A says: Be careful! B is a devil!"(A is different from B), and you can assume that at least one of them will consider echo is a devil and says "Be careful! echo is a devil!".

Output
Output the minimum number of devils in the island.

Sample Input
3
echo
bigdog
smalldog
smalldog says: Be careful! bigdog is a devil!
bigdog says: Be careful! echo is a devil!
4
echo
Lethe
bigdog
smalldog
Lethe says: Be careful! bigdog is a devil!
smalldog says: Be careful! echo is a devil!
bigdog says: Be careful! smalldog is a devil!

Sample Output
1
2

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-06-07 15:52
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序