CF591B.Rebranding

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 x__i by y__i, and all the letters y__i by x__i. 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 x__i coincides with y__i. 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.

一家规模虽小但十分自豪的公司的名称由 nn 个小写英文字母组成。该公司决定尝试品牌重塑(rebranding)——一种积极的市场营销策略,包括一系列措施来更改品牌本身(涵盖公司及其所生产的产品)或其组成部分:名称、标识(logo)、标语(slogan)。他们决定首先从名称入手。

为此,该公司连续聘请了 mm 位设计师。每当公司聘请第 ii 位设计师时,他便会立即参与新公司名称的创作,具体操作如下:他取当前最新版本的名称,并将其中所有字母 xix_i 替换为 yiy_i,同时将所有字母 yiy_i 替换为 xix_i,从而得到一个新版本。注意,这些字母中可能有某些并未在字符串中出现;也可能出现 xi=yix_i = y_i 的情况。经过最后一位设计师工作后所得的名称版本,即成为该公司的新名称。

经理阿尔卡季(Arkady)最近刚入职该公司,但已深深浸润于团队合作的精神之中,因而非常担忧此次品牌重塑能否成功。很自然地,他迫不及待地想要知道公司最终将获得怎样的新名称。

请满足阿尔卡季的好奇心,告诉他最终的公司名称。

输入格式

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the length of the initial name and the number of designers hired, respectively.

The second line consists of n 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 x__i and y__i.

输入的第一行包含两个整数 nn 和 mm(1 ≤ n, m ≤ 200 0001 ≤ n, m ≤ 200\,000),分别表示初始名称的长度以及所雇佣的设计师人数。

第二行由 nn 个小写英文字母组成,表示该公司的原始名称。

接下来的 mm 行描述了各位设计师的操作:其中第 ii 行包含两个用空格分隔的小写英文字母 xix_i 和 yiy_i。

输出格式

Print the new name of the corporation.

输出该公司的新名称。

输入输出样例

  • 输入#1

    6 1
    police
    p m

    输出#1

    molice
  • 输入#2

    11 6
    abacabadaba
    a b
    b c
    a d
    e g
    f a
    b b

    输出#2

    cdcbcdcfcdc

说明/提示

In the second sample the name of the corporation consecutively changes as follows:

在第二个样例中,公司名称依次变化如下:

输入解题思路,AI测评打分。不知道怎么写?

首页