Riddle Me This
You are an adventurer who has travelled far and wide to meet the elusive Sphinx - and obtain its treasures for yourself. After many days of journeying you uncover the Sphinx's riddle.
I guard
hidden relics. Each pair of relics is bound by truths... or lies. Use my clues to determine their values - or prove that I deceive you.
Each relic has an unknown integer value. You are given information regarding the values of these relics, and you need to determine if the information is contradictory and the Sphinx is deceiving you, the information is insufficient (i.e. there could be multiple valid assignments), or if there is a single valid assignment, in which case you can obtain the Sphinx's riches.
Input
The first line contains 2 integers (
).
represents the number of relics, and
represents the number of clues you are given.
The next lines each contain a clue of the form
u v w t
: indices of two relics (1 indexed) -
: an integer -
: either 0 or 1
If , the statement means
. If
, the statement means
.
Output
Determine if the constraints given by the clues lead to a contradiction, multiple possible assignments, or a single unique assignment.
- If the information is inconsistent, output
contradiction. - If the information is insufficient (i.e. there are multiple valid assignments), output
insufficient. - If there is exactly one valid assignment, output the values of all relics in order on a single line. It is possible for the values to be negative.
Clarifications
- We note that all relics have integer values, so if a set of clues would assign a relic a non-integer value you should output
contradiction. I.e.and
will assign
, which is impossible.
- You might be able to determine that there is definitely
insufficientinformation, but later on find acontradiction. In this case, you should printcontradiction. I.e., if there is both insufficient and contradiction,contradictionshould take precedence.
Example
Input 1
3 3
1 2 5 1
2 3 3 1
1 3 20 1
Output 1
contradiction
We are told
This implies that
. However, we are given
, so the Sphinx is playing a cruel trick on us.
Input 2
3 3
1 2 5 1
2 3 3 1
1 3 8 0
Output 2
8 3 0
We know
The first two tell us that
. This and the third clue tell us that
. We can then deduce that
, and
.
Input 3
3 2
1 2 5 1
2 3 3 1
Output 3
insufficient
We know
This tells us
, but this provides infinite possible assignments, so there is insufficient information to tell the values of the relics.
Input 4
1 1
1 1 3 1
Output 4
contradiction
The sole clue tells us that , but this is clearly impossible as
for any
.
Input 5
3 2
1 2 5 0
3 3 1 1
Output 5
contradiction
Although there is insufficient information to fix 1 and 2, and you can figure that out first, the second clue also contains a contradiction: , and this takes precedence.
Comments