Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- int main()
- {
- int a,b,x,y,k=0;
- cin>>b>>a;
- vector<int>par[a+1];
- bool v[a+1];
- for(int i=0;i<b;i++)
- {
- cin>>x>>y;
- par[x].push_back(y);
- par[y].push_back(x);
- }
- for(int i=0;i<a;i++)
- {
- v[i]=false;
- }
- int s,ttl;
- cin>>s>>ttl;
- queue<int>Q;
- Q.push(s);
- Q.push(ttl);
- v[s]=true;
- while(!Q.empty())
- {
- int teme=Q.front();
- Q.pop();
- int pat=Q.front();
- Q.pop();
- for(int i=0;i<par[teme].size();i++)
- {
- int sosed=par[teme][i];
- if(!v[sosed] && pat>0)
- {
- Q.push(sosed);
- Q.push(pat-1);
- v[sosed]=true;
- }
- }
- }
- for(int i=0;i<a;i++)
- {
- if(!v[i])
- {
- k++;
- }
- }
- cout<<k;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement