Advertisement
amine99

Untitled

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