CF467D.Fedor and Essay

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to help and wrote the essay for Fedor. But Fedor didn't like the essay at all. Now Fedor is going to change the essay using the synonym dictionary of the English language.

Fedor does not want to change the meaning of the essay. So the only change he would do: change a word from essay to one of its synonyms, basing on a replacement rule from the dictionary. Fedor may perform this operation any number of times.

As a result, Fedor wants to get an essay which contains as little letters «R» (the case doesn't matter) as possible. If there are multiple essays with minimum number of «R»s he wants to get the one with minimum length (length of essay is the sum of the lengths of all the words in it). Help Fedor get the required essay.

Please note that in this problem the case of letters doesn't matter. For example, if the synonym dictionary says that word cat can be replaced with word DOG, then it is allowed to replace the word Cat with the word doG.

在你帮助费多尔(Fedor)于游戏《士兵召唤3》(«Call of Soldiers 3»)中结交朋友之后,他便彻底停止了学习。今天,英语老师让他准备一篇作文。费多尔不愿写这篇作文,于是向亚历克斯(Alex)求助。亚历克斯前来帮忙,并为费多尔写好了作文。但费多尔完全不喜欢这篇作文。现在,他打算借助一本英语同义词词典来修改这篇作文。

费多尔不想改变作文的原意。因此,他唯一允许的修改操作是:依据词典中的一条替换规则,将作文中的某个单词替换成它的一个同义词。费多尔可以执行该操作任意多次。

最终,费多尔希望得到一篇包含尽可能少的字母「R」(不区分大小写)的作文。如果存在多个「R」的数量达到最小值的作文,则他希望从中选出总长度最小的一篇(作文的长度定义为其中所有单词长度之和)。请帮助费多尔获得满足要求的作文。

请注意:本题中字母的大小写不敏感。例如,若同义词词典中注明单词 cat 可被替换为 DOG,则允许将单词 Cat 替换为 doG。

输入格式

The first line contains a single integer m (1 ≤ m ≤ 105) — the number of words in the initial essay. The second line contains words of the essay. The words are separated by a single space. It is guaranteed that the total length of the words won't exceed 105 characters.

The next line contains a single integer n (0 ≤ n ≤ 105) — the number of pairs of words in synonym dictionary. The i-th of the next n lines contains two space-separated non-empty words x__i and y__i. They mean that word x__i can be replaced with word y__i (but not vise versa). It is guaranteed that the total length of all pairs of synonyms doesn't exceed 5·105 characters.

All the words at input can only consist of uppercase and lowercase letters of the English alphabet.

第一行包含一个整数 mm(1≤m≤1051 \le m \le 10^5)—— 表示初始文章中的单词数量。
第二行包含文章的单词,单词之间以单个空格分隔。保证所有单词的总长度不超过 10510^5 个字符。

接下来一行包含一个整数 nn(0≤n≤1050 \le n \le 10^5)—— 表示同义词词典中单词对的数量。
接下来的 nn 行中,第 ii 行包含两个由空格分隔的非空单词 xix_i 和 yiy_i,表示单词 xix_i 可以被替换为单词 yiy_i(但反之不成立)。保证所有同义词对的总长度不超过 5⋅1055 \cdot 10^5 个字符。

输入中的所有单词仅由英文字母的大写和小写字母组成。

输出格式

Print two integers — the minimum number of letters «R» in an optimal essay and the minimum length of an optimal essay.

输出两个整数——最优作文中字母「R」的最少数量,以及最优作文的最短长度。

输入输出样例

  • 输入#1

    3
    AbRb r Zz
    4
    xR abRb
    aA xr
    zz Z
    xr y

    输出#1

    2 6
  • 输入#2

    2
    RuruRu fedya
    1
    ruruRU fedor

    输出#2

    1 10

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

首页