Banner Tour
YOU: "Your job was putting up Marcus's banners."
RITISHA: "Yeah. I was hoping to do something different. I had this idea for a photo wall — pictures from the last few years of ACPC, plus a polaroid camera so people could add new ones through the night."
YOU: "What happened?"
RITISHA: "Kevin said he already had a photo booth planned and just needed someone on banners. So that became my job. Then a few hours later I watch Zach setting up basically my exact idea."
YOU: "Did you speak to Kevin about it?"
RITISHA: "I wish. I was up a ladder most of the afternoon."
YOU: "And after that?"
RITISHA: "Josh grabbed me for his little interview. Stood there talking to a camera for ten minutes, feeling silly."
After hanging up Marcus' banners, Ritisha wants to check them thoroughly.
The venue consists of rooms, numbered from
to
and connected by
directed corridors. Ritisha starts at room
and walks along the corridors until she reaches a dead end: a room with no outgoing corridors. It is guaranteed that a dead end is reachable (directly or indirectly) from every room.
Some rooms contain one of Marcus' banners. Ritisha checks a banner every time she enters a room with one, even if she has checked it before. Starting at room also counts as one visit.
The corridor structure is constrained as follows:
Every room has at most one incoming corridor, except for rooms lying on a cycle.
The rooms of each cycle collectively have exactly one incoming corridor from outside the cycle.
All cycles are pairwise disjoint.
Every room is reachable from room
.
Equivalently, contracting each cycle into a single node yields a tree rooted at room .
Is it possible for Ritisha to walk from room to some dead end, while checking banners exactly
times?
Input
The first line contains three integers ,
, and
(
,
): the number of rooms, the number of corridors, and the exact number of banner checks Ritisha wants.
The second line contains integers
, each
or
, where
if room
has a banner and
otherwise.
Each of the next lines contains two integers
and
(
), denoting a directed corridor from room
to room
.
Output
If it is possible for Ritisha to walk through the venue and reach a dead end while checking banners exactly times, output
Yes. Otherwise, output No.
Example
Input 1
6 6 6
1 1 0 0 0 1
1 2
2 3
3 1
1 4
4 5
4 6
Output 1
Yes
Ritisha can check on the banners exactly times by following the walk
.
Ritisha starts at room
, checking the banner there.
check so far.
She walks the cycle
twice, re-entering room
each time. Each pass through the cycle checks the banners in rooms
and
, for
checks per loop.
more checks, bringing the total to
.
After the second loop, she leaves the cycle, continuing on to room
(no banner) and then room
, checking the banner there.
more check, for a total of
.
Room
has no outgoing corridors, so Ritisha's walk ends there, having checked on banners exactly
times.

Input 2
9 12 5
0 0 1 1 1 0 0 0 1
1 1
1 2
2 3
3 1
1 4
4 5
5 6
6 7
6 3
2 8
8 2
8 9
Output 2
No
Ritisha can check on the banners exactly ,
, or
times, among infinitely many other achievable values, but
is not one of them. She can never reach a dead end after checking the banners exactly
times.

Input 3
2 2 9999
1 0
1 1
1 2
Output 3
Yes
Comments