Problem A
References |
Problem B
Sum of powers |
Problem C
Game |
Problem D
Crossword |
Problem E
Magic of David Copperfield |
Problem F
Puncher |
Problem G
Flying Stars |
Problem H
Divide et unita |
Input file | INPUT.TXT |
Output file | OUTPUT.TXT |
Time-limit/Test | 10 seconds |
Starting the game the child first of all chooses three different integers L, K and Q within the range between 1 and N. Then he places one pawn into the circle number L and another one into the circle number K, whereupon he begins to move them using the following rules:
Input
The first line of the input file contains integers N, L, K, Q separated by spaces. The second line consists of N integers c1, c2, ... , cn, separated by spaces, in the given order, where ci is the color of the circle number i. The third line consists of a single integer M (0<=M<=10000) denoting the total number of segments. Then follow M lines, each containing a description of one oriented segment. Each segment is described by three integer numbers Aj, Bj, Cj, separated by spaces, where A and B are the numbers of the circles connected by the j-th segment with direction from Aj to Bj, and Cj represents the color of this segment.
Output
The first line of the output file should contain the word "YES", if the game can come to the end, and "NO" otherwise (without quotes). If the answer is "YES", the second line of the output should contain just a single integer - the minimum number of the moves the child should make to finish the game.
Sample input
5 3 4 1 2 3 2 1 4 8 2 1 2 4 1 5 4 5 2 5 1 3 3 2 2 3 2 4 5 3 1 3 5 1Output for the sample input
YES 3