#P9545. [湖北省选模拟 2023] 环山危路 / road
[湖北省选模拟 2023] 环山危路 / road
Problem Description
Country R has cities, numbered from to . Between every pair of cities there are roads, forming a graph. However, these roads are poorly built: each road has a fixed direction, and cars can only travel in that direction. Also, each road is one-time use, meaning at most one car can pass through it.
Now Country R is making a disaster prevention and mitigation plan. You need to help Country R compute, if city suffers a disaster, and the cities have enough relief supplies (you may assume each of them has supplies that can load infinitely many cars), then at most how many cars of supplies can be transported from these cities to . Cars can only use the one-time roads between cities, but before reaching , a car may pass through multiple cities and multiple roads for transfer.
Input Format
There are lines in total.
The first line contains two positive integers , denoting the number of cities and the number of queries.
Lines to each contain a string of length . In line , column indicates whether there is a road from to ( means yes, means no).
In the next lines, each line starts with a positive integer , then a positive integer , followed by positive integers . It is guaranteed that contain no duplicates and none of them equals .
Output Format
Output lines, each containing a non-negative integer, representing the answer to the -th query.
5 2
01001
00110
10001
10101
01000
2 2 1 4
5 2 4 1
2
3
见选手目录下的 road/road2.in 与 road/road2.ans。
见选手目录下的 road/road2.in 与 road/road2.ans。
Hint
Sample 1 Explanation
The roads between cities are shown in the figure below:

This is one possible plan corresponding to the answers:
In the first query, one car takes , and another takes .
In the second query, one car takes , one takes , and another takes .
Subtasks
For all testdata, it is guaranteed that , .

Special Property A: it is guaranteed that all queries have the same .
Special Property B: it is guaranteed that the road between and goes from to .
Translated by ChatGPT 5