Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <map>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int n,B1,B2,P;
- cin>>n>>B1>>B2>>P;
- vector <int> kosta(B1);///gradovi na kosta
- vector <int> kiril(B2);///gradovi na kiril
- set<int> kirilSet;
- set<int> kostaSet;
- for(int i=0;i<B1;i++){
- cin>>kosta[i];
- kostaSet.insert(kosta[i]);
- }
- for(int i=0;i<B2;i++){
- cin>>kiril[i];
- kirilSet.insert(kiril[i]);
- }
- int m;///broj na parovi
- cin>>m;
- vector<int> connected[n];
- for(int i=0;i<m;i++){
- int xi,yi;
- cin>>xi>>yi;
- connected[xi-1].push_back(yi-1);
- connected[yi-1].push_back(xi-1);
- }
- for(int i=0; i<n; i++){
- if (connected[i].size() > 1){
- sort(connected[i].begin(), connected[i].end());
- }
- }
- int rez=0;
- for(int i=0;i<kosta.size();i++)
- {
- if(P==0){
- break;
- }
- for(int j : connected[kosta[i]-1]){
- if(kirilSet.count(j+1) == 0 && kostaSet.count(j+1) == 0){
- P--;
- kosta.push_back(j+1);
- kostaSet.insert(j+1);
- rez++;
- }
- }
- }
- cout<<rez;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement