Mahmoud and Ehab and the message
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.
The first line of input contains integers n, k 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.
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.
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
107
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
116
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的更多相关文章
- [CF959B]Mahmoud and Ehab and the message题解
超级大模拟 直接用map吧string对应到编号上来,然后在开个数组把每个编号对应到每个可以互相转化区块上来,预处理出区块的最小值,使用时直接取最小是即可 代码 #include <cstdio ...
- 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 ...
- Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...
- 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 ...
- Codeforces 862B - Mahmoud and Ehab and the bipartiteness
862B - Mahmoud and Ehab and the bipartiteness 思路:先染色,然后找一种颜色dfs遍历每一个点求答案. 代码: #include<bits/stdc+ ...
- Codeforces 862C - Mahmoud and Ehab and the xor
862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...
- Codeforces 862D. Mahmoud and Ehab and the binary string (二分)
题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...
- 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 ...
- Codeforces 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
随机推荐
- MySQL 8 在一台机器上运行多个MySQL实例
可以为每个实例使用一个MySQL Server二进制程序,也可以为不同实例使用同一个MySQL Server二进制程序. 不管哪一种选择,部分参数可能需要不同配置,以避免多个实例之间的冲突. 可能需要 ...
- 1.python数据类型详解
python数据类型分类 1).数值型:整数型(int).浮点型(float).布尔型(bool 取值:True.False) 2).容器类型 : 字符串型(str).列表(list).元祖(tupl ...
- Element节点
Element节点对象对应网页的 HTML 元素.每一个 HTML 元素,在 DOM 树上都会转化成一个Element节点对象(以下简称元素节点).元素节点的nodeType属性都是1.Element ...
- jQuery---钢琴案例 (按下1-9数字键,能触发对应的mouseenter事件)
钢琴案例 (按下1-9数字键,能触发对应的mouseenter事件) 1. 结合之前的学习,主要内容,就是on注册keyup事件,函数里传入e, 用e.keyCode,来获取1-9的数字的范围. 如果 ...
- SQL Server数据库、表、数据类型基本概念
一.SQL Server的数据存储结构 SQL Server是一个数据库管理系统,需要以有效方式存储高容量数据.要更好地理解SQL Server处理数据的方式,就需要了解数据的存储结构. 1.文件类型 ...
- Jenkins 插件安装问题
插件安装问题 尝试修改更新站点为可用的镜像站点 打开 Jenkins > Manage Jenkins > Manage Plugins > Advanced,将 Update Si ...
- Qt文件发布
1.打开Qt文件夹下的,其他版本可能为Qt (版本号)for Desktop cmd 2.将Release文件下的exe文件复制到别的文件夹,我这里为G:\Qt\QT_project\ff 3.在Qt ...
- C++文件读写demo
一.常用文件打开方式 二.读写文件步骤(文本文件) 1.写文件步骤 1)#include <fstream> //包含头文件 2)ofstream ofs; //创建流对象 3)ofs.o ...
- Java不同单词个数统计
描述 编写一个程序,输入一个句子,然后统计出这个句子当中不同的单词个数.例如:对于句子“one little two little three little boys”,总共有5个不同的单词:one, ...
- 今日头条 SEO 研究,值得深思的 5 个问题
在做SEO的过程中,实际上,我并不是“技术挂”更多的是基于搜索原理与大量的实战,总结相关的经验,这么多年,经常养成一个小习惯,总是记录一些工作中遇到的一些小问题与小技巧. 特别是2017年,12月份开 ...