#P3163. [CQOI2014] 危桥

    ID: 2212 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2014重庆各省省选网络流最大流

[CQOI2014] 危桥

Description

Alice and Bob live in a country consisting of NN islands, numbered from 00 to N1N-1. 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 ana_n round trips between islands a1a_1 and a2a_2 (a round trip means going from a1a_1 to a2a_2 and then back from a2a_2 to a1a_1). Meanwhile, Bob wants to make bnb_n round trips between islands b1b_1 and b2b_2. 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: NN, a1a_1, a2a_2, ana_n, b1b_1, b2b_2, bnb_n.
Then follows an NN-by-NN symmetric matrix of uppercase letters. The entry at row ii and column jj describes the connection between islands numbered i1i-1 and j1j-1: 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, 4N504 \leq N \leq 50, 0a1,a2,b1,b2N10 \leq a_1, a_2, b_1, b_2 \leq N-1, 1an,bn501 \leq a_n, b_n \leq 50.

Translated by ChatGPT 5