Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<queue>
- #include <vector>
- using namespace std;
- int main()
- {
- int gradovi;
- cin>>gradovi;
- int b1;
- cin>>b1;
- int b2;
- cin>>b2;
- int p;
- cin>>p;
- int ko[b1];
- int ki[b2];
- int p1=0;
- vector<int>graph[gradovi+10];
- for(int i=0; i<b1; i++){
- cin>>ko[i];
- }
- for(int i1=0; i1<b2; i1++){
- cin>>ki[i1];
- }
- int m;
- cin>>m;
- for(int k=0; k<m; k++){
- int a,b;
- cin>>a>>b;
- graph[a].push_back(b);
- graph[b].push_back(a);
- }
- queue<int>q;
- for(int j=0; j<b1; j++){
- q.push(ko[j]);
- }
- bool niza[gradovi+10];
- for(int h=0; h<=gradovi; h++){
- niza[h]=false;
- }
- for(int h1=0; h1<b2; h1++){
- int p=ki[h1];
- niza[p]=true;
- }
- for(int h2=0; h2<b1; h2++){
- int p1=ko[h2];
- niza[p1]=true;
- }
- while(!q.empty()){
- int c=q.front();
- q.pop();
- for(int u=0; u<graph[c].size(); u++){
- int cc=graph[c][u];
- if(niza[cc]==false){
- q.push(cc);
- niza[cc]=true;
- p1+=1;
- }
- }
- }
- if(p1>p){
- p1=p;
- }
- cout<<p1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement