[CF959B]Mahmoud and Ehab and the message题解

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

代码

#include <cstdio> 
#include <iostream>
#include <map>
#define ll long long
#define min(a,b) ((a<b)?a:b)

using namespace std;

inline ll read(){
    ll x = 0; int zf = 1; char ch = ' ';
    while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}

map<string, int> mp;
string s[100005];
int a[100005];
int dy[100005];
int val[100005];

int main(){
    int n = read(), k = read(), m = read();
    for (int i = 1; i <= n; ++i)
        cin >> s[i];
    for (int i = 1; i <= n; ++i)
        a[i] = read(), mp[s[i]] = i;
    int q;
    for (int i = 1; i <= k; ++i)
        val[i] = 2147483647;
    for (int i = 1; i <= k; ++i){
        q = read();
        for (int j = 0; j < q; ++j){
            int t = read();
            dy[t] = i, val[i] = min(val[i], a[t]);
        }
    }
    string c; ll ans = 0;
    for (int i = 1; i <= m; ++i){
        cin >> c;
        ans += val[dy[mp[c]]];
    }
    printf("%lld", ans);
    return 0;
}
posted @ 2019-05-20 18:57  LinZhengmin  阅读(207)  评论(0编辑  收藏  举报

Contact with me