Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define loop(i,b,e) for(auto i=b;i<=e;i++)
- #define PB push_back
- #define F first
- #define S second
- #define sf scanf
- #define pf printf
- typedef long long LL;
- typedef vector<int> VI;
- typedef vector<LL> VLL;
- const int N=1e5+1;
- LL ans,cost;
- int n,c,k,sz;
- string s,tmp;
- vector<string> words,msg;
- map<string,LL> m;
- int main()
- {
- sf("%d %d %d",&n,&k,&c);
- loop(i,1,n) {
- cin >> s;
- words.PB(s);
- }
- loop(i,0,n-1) {
- scanf("%d",&cost);
- m[words[i]] = cost;
- }
- loop(i,0,k-1) {
- LL mn = 1e12;
- sf("%d",&sz);
- int v[sz];
- loop(j,0,sz-1) {
- sf("%d",&v[j]);
- tmp = words[v[j]-1];
- mn = min(mn,m[tmp]);
- }
- loop(j,0,sz-1) {
- tmp = words[v[j]-1];
- m[tmp] = mn;
- }
- }
- loop(i,1,c) {
- cin >> s;
- ans += m[s];
- }
- pf("%lld",ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement