Painted Corridors

아직 제출이 없습니다시간 제한5초메모리 제한512 MB

문제

The Institute of Colorfully Painted Corridors is planning the construction of a new building. The building has numerous junctions, and corridors that each connect a pair of junctions. The corridors will be painted by amazing new painting robots that drive along the corridors and paint all the walls as they go. The architect has specified the colors of some of the corridors, which may be red, orange, yellow, green, blue, or purple. However, there is only a budget for three painting robots, so there will be a single robot for each primary color (red, yellow, or blue). In addition, these robots are the cheapest possible version, and cannot turn their paint sprayer off (though they can go as fast or as slow as desired with no problems; they can even stop moving entirely).

If a corridor needs to be painted a secondary color (orange, green, or purple), in order for the paints to mix properly, the two robots with the appropriate primary colors must travel down the corridor in the same direction at the same time to create the correct color. The color mixing rules are: orange = red + yellow, green = yellow + blue, and purple = red + blue. A corridor that is unspecified in the plan may be painted any color, or left unpainted.

Corridors may be painted multiple times, provided that each time they are painted with the correct color. Corridors with no specified color can be painted multiple times with different colors. All corridors can be travelled along in both directions. The robots may end up at any junctions after painting all the corridors.

Given the architect’s design, is it possible for the painting robots to paint the corridors the desired colors?

입력

The first line of input contains five integers, nn (2n1002 \le n \le 100), mm (1mn(n1)21 \le m \le \frac{n \cdot (n-1)}{2}), rr, bb and yy (1r,b,yn1 \le r, b, y \le n), where nn is the number of junctions, mm is the number of corridors, and rr, bb and yy are the initial junctions of the red, blue, and yellow painting robots respectively. Junctions are numbered 11 through nn. Each of the next mm lines contains two integers ii, jj (1i<jn1 \le i < j \le n), and a single character cc which is one of R, O, Y, G, B, P, X. The integers ii, jj indicate that there is a corridor between junction ii and junction jj, with cc indicating the desired color. (R, O, Y, G, B, P, X, corresponding to Red, Orange, Yellow, Green, Blue, Purple, and Unspecified, respectively.) There is at most one corridor between each pair of junctions.

출력

Output a single integer, 11 if it is possible to paint the corridors as described and 00 otherwise.