Untitled
void solve() { int n,k,m;cin>>n>>k>>m; map<string,int> mp;int arr[n+1]; For(n){ string s;cin>>s; mp[s] =i+1; } for(int i = 1;i<=n;i++) cin>>arr[i]; while (k--) { int g;cin>>g; if(g==1){ int trash;cin>>trash; continue; } int curr = 0,prev=-1; for(int j = 1;j<=g;j++){ cin>>curr; if(prev==-1){ prev =curr; continue; } if(arr[curr]<arr[prev]) arr[prev] = arr[curr]; else arr[curr] = arr[prev]; prev = curr; } } int sum = 0; for(int i =1;i<=m;i++){ string s;cin>>s; cout << s <<' '<<mp[s]<<' '<<arr[mp[s]]<< endl; sum += arr[mp[s]]; } cout << sum << endl; }
Leave a Comment