天天看點

HDU 2828 DLX搜尋Lamp

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 771    Accepted Submission(s): 230

Special Judge

Problem Description

There are several switches and lamps in the room, however, the connections between them are very complicated. One lamp may be controlled by several switches, and one switch may controls at most two lamps. And what’s more, some connections

are reversed by mistake, so it’s possible that some lamp is lighted when its corresponding switch is “OFF”!

To make things easier, we number all the lamps from 1 to N, and all the switches 1 to M. For each lamps, we give a list of switches controlling it. For example, for Lamp 1, the list is “1 ON 3 OFF 9 ON”, that means Lamp 1 will be lighted if the Switch 1 is

at the “ON” state OR the Switch 3 is “OFF” OR the Switch 9 is “ON”.

Now you are requested to turn on or off the switches to make all the lamps lighted.

Input

There are several test cases in the input. The first line of each test case contains N and M (1 <= N,M <= 500), then N lines follow, each indicating one lamp. Each line begins with a number K, indicating the number of switches controlling

this lamp, then K pairs of “x ON” or “x OFF” follow.

Output

Output one line for each test case, each contains M strings “ON” or “OFF”, indicating the corresponding state of the switches. For the solution may be not unique, any correct answer will be OK. If there are no solutions, output “-1”

instead.

Sample Input

Sample Output

DLX簡單搜尋,糾結了好久,行為2*m,每一個開關ON,OFF兩種狀态,列為n,代表燈的狀态,然後按照重複覆寫搜尋,不需要估價函數,用一個vis數組記錄開關狀态就行。

代碼: