B - Tags at the Mountain Temple Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 233 点

問題文

山寺の石段には N 枚の札が左から順に並んでおり、それぞれに英小文字が 1 文字ずつ書かれています。左から i 番目の札の文字は、文字列 S の i 文字目です。

高橋君はこれから Q 回、札を入れ替えます。 i 回目には、左から a_i 番目の札と左から b_i 番目の札の位置を入れ替えます。 a_i = b_i のときは何も起こりません。

Q 回の入れ替えがすべて終わったあと、札の文字を左から順に並べた文字列を出力してください。

制約

  • 1 \leq N \leq 100
  • 1 \leq Q \leq 100
  • S は英小文字のみからなる長さ N の文字列
  • 1 \leq a_i \leq N
  • 1 \leq b_i \leq N
  • 入力のうち S 以外はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N Q
S
a_1 b_1
a_2 b_2
\vdots
a_Q b_Q
  • 1 行目には、札の枚数 N と入れ替えの回数 Q がスペース区切りで与えられる。
  • 2 行目には、札の文字を表す文字列 S が与えられる。
  • 3 行目から Q 行にわたり、 2 + i 行目には i 回目に入れ替える札の位置 a_i と b_i がスペース区切りで与えられる。

出力

すべての入れ替えが終わったあとの札の文字を左から順に並べた文字列を 1 行で出力せよ。


入力例 1

5 2
abcde
1 3
2 5

出力例 1

ceadb

入力例 2

3 1
xyz
2 2

出力例 2

xyz

入力例 3

4 3
abcd
1 4
2 3
1 4

出力例 3

acbd

入力例 4

3 1
xyz
1 2

出力例 4

yxz

入力例 5

4 3
abcd
1 4
2 1
1 4

出力例 5

adcb

Score : 233 pts

Problem Statement

There are N tags lined up in order from left to right on the stone steps of a mountain temple, each with one lowercase English letter written on it. The letter on the i-th tag from the left is the i-th character of the string S.

Takahashi will now swap tags Q times. On the i-th swap, he swaps the positions of the a_i-th tag from the left and the b_i-th tag from the left. When a_i = b_i, nothing happens.

After all Q swaps are complete, output the string formed by the letters on the tags arranged from left to right.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq Q \leq 100
  • S is a string of length N consisting only of lowercase English letters
  • 1 \leq a_i \leq N
  • 1 \leq b_i \leq N
  • All values in the input except S are integers

Input

The input is given from standard input in the following format:

N Q
S
a_1 b_1
a_2 b_2
\vdots
a_Q b_Q
  • The first line contains the number of tags N and the number of swaps Q, separated by a space.
  • The second line contains the string S representing the letters on the tags.
  • Over Q lines starting from the third line, the (2 + i)-th line contains the positions a_i and b_i of the tags swapped in the i-th operation, separated by a space.

Output

Output, in one line, the string formed by the letters on the tags from left to right after all swaps are complete.


Sample Input 1

5 2
abcde
1 3
2 5

Sample Output 1

ceadb

Sample Input 2

3 1
xyz
2 2

Sample Output 2

xyz

Sample Input 3

4 3
abcd
1 4
2 3
1 4

Sample Output 3

acbd

Sample Input 4

3 1
xyz
1 2

Sample Output 4

yxz

Sample Input 5

4 3
abcd
1 4
2 1
1 4

Sample Output 5

adcb