PivotOJ

Team Change

시간 제한: 3000ms메모리 제한: 1024MB출처: ICPC Rocky Mountain Regional 2021BOJ 24761

문제

Mr. Smith, the physical education teacher at Rocky Mountain High School, likes to take a hands-off approach to teaching gym class. What does that mean? A lot of dodgeball!

For the last few months, the students have been split into the same two teams. But now some students are asking for a change.

Some students want to be assigned to a specific team. Also, certain pairs of students that are currently on opposite teams have become rivals and are unwilling to be on each other's team.

Since Mr. Smith does not want to be complacent he has decided to shuffle the teams. He realizes it is not necessarily possible to form new teams satisfying both of the above constraints. To solve this, he will make some students sit the next game out.

Your job is to help Mr. Smith form the new teams that satisfy the above constraints such that the number of students who must sit out is minimum. Note that the teams do not need to have the same number of players nor does a team have to have any players at all.

입력

The first line of input contains two integers NN (1N10001 \leq N \leq 1\,000), which is the number of students, and RR (0R100000 \leq R \leq 10\,000), which is the number of rivalries.

The next line contains a string which describes the current teams. The string has length NN consisting of characters A and B. The iith character on this line is the team that the iith student is currently playing for.

The next line contains a string which describes the students' requested teams. The string has length NN consisting of characters A, B, and ?. The iith character on this line is the desired team of the iith student or ? if the student has no preference.

The next RR lines describe the rivalries. Each line contains two distinct integers ii (1iN1 \leq i \leq N) and jj (1jN1 \leq j \leq N), which indicates that student ii and student jj are rivals. Rival students are on different teams. No rival pair of students will be reported more than once.

출력

Display a valid team formation with the minimum number of students sitting out. If the iith student is to sit out of the game, the iith character should be X. Otherwise, the iith character of this line should either be A or B, indicating which team this player is assigned to.

If there are multiple possible solutions, display any of them.

예제

예제 1

입력
5 4
AAABB
??AAA
1 4
2 4
3 4
3 5
출력
BBXAA

예제 2

입력
2 1
AB
AA
1 2
출력
XA

예제 3

입력
8 8
ABBABAAA
?B?ABBAB
1 2
4 3
6 5
4 5
1 5
2 8
3 7
2 4
출력
BXBAXBAB
코드를 제출하려면 로그인하세요.