Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from 1 to n. Some words have the same meaning so there are k groups of words such that all the words in some group have the same meaning.

Mahmoud knows that the i-th word can be sent with cost ai. For each word in his message, Mahmoud can either replace it with another word of the same meaning or leave it as it is. Can you help Mahmoud determine the minimum cost of sending the message?

The cost of sending the message is the sum of the costs of sending every word in it.

Input

The first line of input contains integers nk and m (1 ≤ k ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively.

The second line contains n strings consisting of lowercase English letters of length not exceeding 20 which represent the words. It's guaranteed that the words are distinct.

The third line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) where ai is the cost of sending the i-th word.

The next k lines describe the groups of words of same meaning. The next k lines each start with an integer x (1 ≤ x ≤ n) which means that there are x words in this group, followed by x integers which represent the indices of words in this group. It's guaranteed that each word appears in exactly one group.

The next line contains m space-separated words which represent Mahmoud's message. Each of these words appears in the list of language's words.

Output

The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning.

Examples
input

Copy
5 4 4
i loser am the second
100 1 1 5 10
1 1
1 3
2 2 5
1 4
i am the second
output

Copy
107
input

Copy
5 4 4
i loser am the second
100 20 1 5 10
1 1
1 3
2 2 5
1 4
i am the second
output

Copy
116
Note

In the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.

In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116.


阅读理解题

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
//#include <xfunctional>
#define ll long long
#define mod 998244353
using namespace std;
int dir[][] = { {,},{,-},{-,},{,} };
const int maxn = ;
const long long inf = 0x7f7f7f7f7f7f7f7f;
const int INT = 0x3f3f3f3f;
int main()
{
int n, k, m;
cin >> n >> k >> m;
vector<string> s(n + );
map<string, int> mp;
map<int, int> mpn;
for (int i = ; i <= n; i++)
{
cin >> s[i];
mp[s[i]] = i;
}
for (int i = ; i <= n; i++)
{
int t;
cin >> t;
mpn[i] = t;
}
for (int i = ; i < k; i++)
{
int all,minn=INT;
cin >> all;
vector<int> v(all);
for(int i=;i<all;i++)
{
cin >> v[i];
minn = min(minn, mpn[v[i]]);
}
for (int i = ; i < all; i++)
{
mpn[v[i]] = minn;
}
}
ll res=;
while (m--)
{
string ss;
cin >> ss;
res += mpn[mp[ss]];
}
cout << res;
return ;
}

Mahmoud and Ehab and the message的更多相关文章

  1. [CF959B]Mahmoud and Ehab and the message题解

    超级大模拟 直接用map吧string对应到编号上来,然后在开个数组把每个编号对应到每个可以互相转化区块上来,预处理出区块的最小值,使用时直接取最小是即可 代码 #include <cstdio ...

  2. Codeforces 862A Mahmoud and Ehab and the MEX

    传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 ...

  3. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  4. E - Mahmoud and Ehab and the bipartiteness CodeForces - 862B (dfs黑白染色)

    Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipa ...

  5. Codeforces 862B - Mahmoud and Ehab and the bipartiteness

    862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...

  6. Codeforces 862C - Mahmoud and Ehab and the xor

    862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...

  7. Codeforces 862D. Mahmoud and Ehab and the binary string (二分)

    题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...

  8. CF 959 E. Mahmoud and Ehab and the xor-MST

    E. Mahmoud and Ehab and the xor-MST https://codeforces.com/contest/959/problem/E 分析: 每个点x应该和x ^ lowb ...

  9. Codeforces 959 F. Mahmoud and Ehab and yet another xor task

    \(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...

随机推荐

  1. Linux文件夹被杀死求解?

    Linux中提示cheese.e-calendar-factory 两个文件夹被杀死 程序错误1.cheese process /usr/bin/cheese was killed by signal ...

  2. IDEA如何恢复到以前的代码

    虽然说IDEA的Ctrl+z撤销操作和Ctrl+Shift+Z重做操作为书写代码提供了很大的便利 但是在各种原因不小心失误撤销后又想不起来代码是怎么写的时候就非常尴尬,这时候就需要代码恢复到以前的状态 ...

  3. shell awk学习3

    需求: 某文件aa的内容如下: a/p1/p2b/pp1c/ppp1/ppp3d/p1/p2/p3e/p1/p2/p3/p4 期望输出结果: a /p1 /p2 b /pp1 c /ppp1 /ppp ...

  4. Prometheus的查询语法是PromQL基本语法

    PromQL(Prometheus Query Language)是 Prometheus 自己开发的表达式语言,语言表现力很丰富,内置函数也很多.使用它可以对时序数据进行筛选和聚合. 1- Prom ...

  5. 【学习笔记】BP神经网络

    转自 huaweizte123的CSDN博客  链接 https://blog.csdn.net/huaweizte123/article/details/78803045 第一步.向前传播得到预测数 ...

  6. 汇编语言中LABEL伪指令的功能?

    LABEL 一般用作定义变量和标号的属性,它是与紧接着的下一条变量和标号定义语句相关的,其类型可以为BYTE.WORD.DWORD.QWORD.NEAR.FAR等等.用法为:buffer(变量) LA ...

  7. 安装DHCP到CentOS(YUM)

    运行环境 系统版本:CentOS Linux release 7.3.1611 (Core) 软件版本:DHCP-x 硬件要求:无 安装过程 1.安装YUM源,由EPEL提供 [root@localh ...

  8. KC开发组官方网站

    KC开发组,简称KC,又叫KC Team,是Kong Che Team(空车开发组)的缩写 是由ordosyz(某乡村小学)的CSP2019退役OIer(信息学奥林匹克竞赛选手) 于2020年2月23 ...

  9. 小白月赛22 A : 操作序列

    A:操作序列 析题得说: 考察点 : 模拟,STL库容器的使用 坑点 : 区间不要搞丢东西 难点 : 这个题比较变态的是我们不知道每次输入每行是一个数还是两个数,就需要进行判断, 怎么判断呢?用 sc ...

  10. java学习笔记之反射—Class类实例化和对象的反射实例化

    反射之中所有的核心操作都是通过Class类对象展开的,可以说Class类是反射操作的根源所在,但是这个类的实例化对象,可以采用三种方式完成. java.lang.Class类的定义: public f ...