#P11146. 「SFMOI Round I」Strange Train Game
「SFMOI Round I」Strange Train Game
Description
Hint: A brief and formalized statement is provided at the end of the description.
A train called SFM consists of carriages, numbered from to . Carriage indexed has comfort , where stands for comfortable, and stands for uncomfortable. We want to minimize the indices of comfortable carriages, in other words, to maximize the lexicographical order of .
In order to do that, we have another train consists also carriages, whose comfortable numbers are denoted by . There are operations available, the -th operation has two parameters , which denotes swapping and for every .
You can choose to perform or not to perform the operations in a given order. There are ways to do that, so we turned to you to choose the best one to maximize the lexicographical order of . You only need to output the final result.
Formally: Two binary string are given, whose length are both . Also, integers is given. For , by this order, excecute the precedure:
- Choose to perform -th operation or not.
- If so, for , swap and .
You need to maximize the lexicographical order of and output the final result.
Input Format
The first line contains two integers —the number of carriages and the number of operations, respectively.
The second line contains a binary string , where is the comfort of the train SFM.
The second line contains a binary string , where is the comfort of another train.
The following lines, the -th line contains two integers , to describe the -th operation.
Output Format
Output one line containing a binary string—the best result after the operations.
10 5
0101011001
0101001110
5 10
2 6
1 10
6 6
3 4
0101011110
Hint
本题采用捆绑测试。
- Subtask 1 (20 pts): ;
- Subtask 2 (30 pts): are pairwise distinct, ;
- Subtask 3 (30 pts):;
- Subtask 4 (20 pts):No further constraints.
It is guaranteed that
- ;
- .
京公网安备 11011102002149号