【编程题解】Good or bad?

Description

There are two kinds of people living on an island, those who are good and those who are bad.

A good man always speaks the truth, and a bad man always lies.

Each member on the island has an integer number to distinguish each member like ID.

Now you have n opportunities to ask questions, but the content of the question can only be to ask one resident whether the other resident is a good person, please determine the identity of each resident according to the collected answers.

 

Input

The input contains multiple sets of test cases.

The first line of each set of test cases contains three non-negative integers N,P1 and P2, where N is the total number of times you can ask questions, P1 isthe total number of good people, and P2 is the total number of bad people.

The next n lines each contain two integers xi, yi and a string Ai, where xi, yi is thenumber of the people on the island, and you're going to ask the people numbered xi whether the people numbered yi are good people,

ai is his answer, if ai is "yes", he answers you "yes", if ai is "no", he answers you "no".

xi,yi might be the same, which means you're asking whether the person is a good person.

When the input is a "0, 0, 0" on one line, the input is terminated.

Datarange:1≤xi,yi≤p1+p2,1≤n<1000,1≤p1,p2<300

 

Output

For each set of test cases, if the query yields enough information for you to determine the identity of each resident, output the Numbers of all the good people on oneline, and then "end" on another line to indicate the end of the use case output.

If the information obtained is insufficient to determine the identity of each resident, then "no" is output, which also occupies one line.

Sample Input 1 

2 1 1
1 2 no
2 1 no
0 0 0

Sample Output 1

no

Sample Input 2  

2 2 1
1 2 yes
2 3 no
0 0 0

 Sample Output 2

1
2
end

 

Personal Answer  (using language:JAVA)  Not necessarily right


public class Main {
    public static void main(String[] args) {
        System.out.println("Unsolved");
    }
}

Welcome to communicate!

 

展开阅读全文
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值