시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
5 초 512 MB 5 1 1 20.000%

문제

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, $n$ ($2 \le n \le 100$), $m$ ($1 \le m \le \frac{n \cdot (n-1)}{2}$), $r$, $b$ and $y$ ($1 \le r, b, y \le n$), where $n$ is the number of junctions, $m$ is the number of corridors, and $r$, $b$ and $y$ are the initial junctions of the red, blue, and yellow painting robots respectively. Junctions are numbered $1$ through $n$. Each of the next $m$ lines contains two integers $i$, $j$ ($1 \le i < j \le n$), and a single character $c$ which is one of R, O, Y, G, B, P, X. The integers $i$, $j$ indicate that there is a corridor between junction $i$ and junction $j$, with $c$ 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, $1$ if it is possible to paint the corridors as described and $0$ otherwise.

예제 입력 1

6 5 1 2 5
1 3 X
2 3 X
3 4 P
4 5 X
4 6 Y

예제 출력 1

1

예제 입력 2

6 5 1 2 5
1 3 X
2 3 X
3 4 O
4 5 X
4 6 Y

예제 출력 2

0

예제 입력 3

6 5 1 2 5
1 3 X
2 3 X
3 4 P
4 5 X
4 6 G

예제 출력 3

1