| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12605 | Rebranding |
|
| 12604 | N-Queens M-Rooks Problem |
|
Description
The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.
For this purpose the corporation has consecutively hired m designers. Once a company hires the i-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters xi by yi, and all the letters yi by xi. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that xi coincides with yi. The version of the name received after the work of the last designer becomes the new name of the corporation.
Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can’t wait to find out what is the new name the Corporation will receive.
Satisfy Arkady’s curiosity and tell him the final version of the name.
This Problem is reproduced from http://codeforces.com/problemset/problem/591/B
Input
The first line of the input contains two integers n and mm (1 ≤ n, m ≤ 200,000)— the length of the initial name and the number of designers hired, respectively.
The second line consists of nn lowercase English letters and represents the original name of the corporation.
Next m lines contain the descriptions of the designers’ actions: the i-th of them contains two space-separated lowercase English letters xi and yi.
Output
Print the new name of the corporation.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
N queens problem asks how many ways to place N non-attacking queens on an N×N chessboard.
For example, there’re 2 solutions for N = 4:
( 0 means empty spot, Q means queen. )
0 Q 0 0 0 0 Q 0
0 0 0 Q Q 0 0 0
Q 0 0 0 0 0 0 Q
0 0 Q 0 0 Q 0 0
While, there’s no solution for N = 2:
Below is the all placements. All of them contains queens threaten each other.
Q Q Q 0 Q 0 0 Q 0 Q 0 0
0 0 Q 0 0 Q Q 0 0 Q Q Q
Let’s define a new problem “N-Queens M-Rooks Problem”.
It asks how many ways to place N queens and M rooks on an (N+M)×(N+M)( chessboard such that no two of queens or rooks can attack each other in 1 step.
For N = 1, M = 2, there’re 4 solutions:
( 0 means empty spot, Q means queen, R means rook. )
Q 0 0 0 R 0
0 0 R R 0 0
0 R 0 0 0 Q
0 R 0 0 0 Q
0 0 R R 0 0
Q 0 0 0 R 0
Possible move of Queen:

Possible move of Rook:

Input
There’re multiple testcases.
Each testcase is consisted of 2 integers N,M on one line.
It’s guaranteed that:
- 0 ≤ N, M ≤ 9
- 1 ≤ N+M ≤ 9
Output
Print the number of solution for N-Queens M-Rooks Problem for every testcase.
Remember ‘\n’ on the end of line.