Shop Till You Drop
Today, you and your friends are going to hit up Khan el-Khalili, Cairo, a famous bazaar founded in the late 14th century. It's still going strong today, with many luxuries to buy and foods to eat.
In the bazaar, there are vendors, numbered from
to
, connected by
paths. Beginning at vendor
, you and your friends will perform the following operation
times:
- Buy something from the current vendor.
- Optionally, move to any vendor connected to your current vendor by a path.
Once your shopping is finished, you'll be too tired to continue, and drop to the ground. Some vendors have benches where customers can rest. If you end your trip at a vendor with a bench, you can take a break, and the trip is considered successful. Otherwise, the trip is considered a failure.
You start to wonder: how many unique sequences of vendors can you buy stuff from, that results in a successful trip?
Input
The first line contains an three integers (
),
(
),
(
), the number of vendors in the bazaar, the number of paths connecting them, and the number of operations you will perform.
The next line contains integers
(
).
if the
th vendor has a bench, and
otherwise.
The next lines are in the form \(x \: y\) (
), indicating that there is a path between vendors
and
.
Each vendor has at most paths coming from it.
Output
Output the number of unique sequences of vendors you can visit, while ending your trip at a vendor with a bench. Since this value may be very large, output it modulo .
Note
You should use Pypy3 for your Python submissions.
Example
Input 1
5 6 2
0 0 1 1 0
1 2
1 3
1 4
1 5
2 3
3 4
Output 1
7
There are ways to traverse the bazaar, starting from vendor
and ending on a vendor with a bench (either vendor
or
). Note that:
- You are allowed to stay at your current position during an operation.
- Staying at
and going to
(
,
,
) is considered distinct from going to
, then staying there (
,
,
).

Input 2
5 6 3
0 0 1 1 0
1 2
1 3
1 4
1 5
2 3
3 4
Output 2
27
Adding more operations makes the number of moves exponentially larger.
Input 4
8 10 1000000000000000000
1 0 1 0 1 1 1 1
1 2
2 3
2 4
2 5
3 5
3 8
4 6
5 6
6 7
7 8
Output 4
277821039
Comments