#P3163. [CQOI2014] 危桥
[CQOI2014] 危桥
Description
Alice and Bob live in a country consisting of islands, numbered from to . Some pairs of islands are connected by bridges. The roads on the bridges are bidirectional, but only one person can pass at a time. Some bridges have become dangerous due to age and can be used at most twice.
Alice wants to make round trips between islands and (a round trip means going from to and then back from to ). Meanwhile, Bob wants to make round trips between islands and . During the whole process, each dangerous bridge can be used at most twice in total, while the other bridges can be used infinitely many times. Can Alice and Bob fulfill their wishes?
Input Format
There are multiple test cases.
For each test case, the first line contains seven space-separated integers: , , , , , , .
Then follows an -by- symmetric matrix of uppercase letters. The entry at row and column describes the connection between islands numbered and : if it is O, there is a dangerous bridge; if it is N, there is a normal bridge; if it is X, there is no bridge.
Output Format
For each test case, output one line. Output “Yes” if they can both fulfill their wishes, otherwise output “No” (without quotes).
4 0 1 1 2 3 1
XOXX
OXOX
XOXO
XXOX
4 0 2 1 1 3 2
XNXO
NXOX
XOXO
OXOX
Yes
No
Hint
Constraints: For all testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号