QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21207. The Continental Cowngress

Statistics

Displeased with Farmer John's leadership, the cows have seceded from the farm and have formed the first Continental Cowngress. Built on the principle of "every cow gets something they want," they've decided on the following voting system:

The $M$ ($1 \leq M \leq 4{,}000$) cows in attendance will vote on $N$ ($1 \leq N \leq 1{,}000$) legislative bills. Each cow casts a "yes" or "no" vote (denoted as '$Y$' or '$N$' in the input) on exactly two (distinct) bills $B_i$ and $C_i$ ($1 \leq B_i, C_i \leq N$). The votes are called $VB_i$ ($VB_i \in \{\text{Y}, \text{N}\}$) and $VC_i$ ($VC_i \in \{\text{Y}, \text{N}\}$), respectively.

Finally, the bills are to be passed or not in such a way that every cow gets her way on at least one of her votes. For example, if Bessie votes "yes" on Bill 1, and "no" on Bill 2, then in any valid solution, it must be the case that either Bill 1 gets passed or Bill 2 gets rejected (or both).

Given the votes of each of the cows, it's your job to figure out which bills will be passed and which bills will be rejected in order to conform to the rules above. If there is no solution, print "IMPOSSIBLE". If there is at least one solution, then for each bill, display:

  • $Y$ if in every solution this bill passes
  • $N$ if in every solution this bill fails
  • ? if there are solutions where this bill passes and solutions where it does not pass

Consider the following set of votes (two for each cow):

       - - - - - BILL - - - - -
         1        2        3
Cow 1   YES      NO
Cow 2   NO       NO
Cow 3   YES               YES
Cow 4   YES      YES

From this, two solutions satisfy every cow:

  • Bill 1 passes (this then satisfies cows 1, 3, and 4)
  • Bill 2 fails (this then satisfies cow 2)
  • Bill 3 could pass or fail (and this is the reason there are two solutions)

In fact, these are the only two solutions, so the answer is the three character string below:

YN?

Input

Read the input from standard input.

  • Line $1$: Two space-separated integers: $N$ and $M$
  • Lines $2 \ldots M+1$: Line $i+1$ describes cow $i$'s votes with four space-separated fields -- an integer, a vote, another integer, and another vote: $B_i$, $VB_i$, $C_i$, $VC_i$

Output

Write the output to standard output.

  • Line $1$: A string with $N$ characters, where the $i$th character is either a "$Y$" if the ith bill must pass, an "$N$" if the ith bill must fail, or a "?" if it cannot be determined whether the bill passes from these votes.

If there is no solution which satisfies every cow, then output the single line "IMPOSSIBLE".

Examples

Input 1

3 4
1 Y 2 N
1 N 2 N
1 Y 3 Y
1 Y 2 Y

Output 1

YN?

Problem credits: Louis Wasserman, 2010

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.