Advertisement
amine99

Untitled

Apr 3rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define loop(i,b,e) for(auto i=b;i<=e;i++)
  5. #define PB push_back
  6. #define F first
  7. #define S second
  8. #define sf scanf
  9. #define pf printf
  10. typedef long long LL;
  11. typedef vector<int> VI;
  12. typedef vector<LL> VLL;
  13.  
  14. const int N=1e5+1;
  15. LL ans,cost;
  16. int n,c,k,sz;
  17. string s,tmp;
  18. vector<string> words,msg;
  19. map<string,LL> m;
  20.  
  21. int main()
  22. {
  23.    sf("%d %d %d",&n,&k,&c);
  24.    loop(i,1,n) {
  25.       cin >> s;
  26.       words.PB(s);
  27.    }
  28.    loop(i,0,n-1) {
  29.       scanf("%d",&cost);
  30.       m[words[i]] = cost;
  31.    }
  32.    loop(i,0,k-1) {
  33.       LL mn = 1e12;
  34.       sf("%d",&sz);
  35.       int v[sz];
  36.       loop(j,0,sz-1) {
  37.          sf("%d",&v[j]);
  38.          tmp = words[v[j]-1];
  39.          mn = min(mn,m[tmp]);
  40.       }
  41.       loop(j,0,sz-1) {
  42.          tmp = words[v[j]-1];
  43.          m[tmp] = mn;
  44.       }
  45.    }
  46.    loop(i,1,c) {
  47.       cin >> s;
  48.       ans += m[s];
  49.    }
  50.    pf("%lld",ans);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement