A complex cryptosystem works as follows:
You have n words and if you put a vertex for any word in the graph, then you will use some edges between them and color each one of them
In this system, a key is defined as follows:
(c1,c2,...,c|c|)*k which means that the order(c1,c2,...,c|c|) repeats k times
For example, the key (1,2)*3 =(1,2,1,2,1,2) (1 and 2 are colors) or the key (3,8,1)*2 = (3,8,1,3,8,1).
So, a color can repeat multiple times as shown in the example.
In order to use two words instead of each other, the set of paths between them must be in the following order:
Note: In a path, a vertex and an edge can be repeated multiple times.
1. The edges in the path must be exactly like the key.
2. The number of paths with the given condition must be greater than or equal p (for security).
You are given a graph with colored edges, key, two vertices, and p.
You need to find out if there is a set of paths that follows the order between those two vertexes.
Input format
Output format
Print YES, if there is a set of paths and NO otherwise.
in the first example our key is (1,2)*1=(1,2) so there is two path between 3 and 2 (3,4,2) and (3,1,2) and p=2 so the answer is YES.(and if p was 3 then answer was NO)