Advertisement
Josif_tepe

Untitled

Nov 21st, 2021
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12. int a,b,x,y,k=0;
  13. cin>>b>>a;
  14. vector<int>par[a+1];
  15. bool v[a+1];
  16. for(int i=0;i<b;i++)
  17. {
  18. cin>>x>>y;
  19. par[x].push_back(y);
  20. par[y].push_back(x);
  21. }
  22. for(int i=0;i<a;i++)
  23. {
  24. v[i]=false;
  25. }
  26. int s,ttl;
  27. cin>>s>>ttl;
  28. queue<int>Q;
  29. Q.push(s);
  30. Q.push(ttl);
  31. v[s]=true;
  32. while(!Q.empty())
  33. {
  34. int teme=Q.front();
  35. Q.pop();
  36. int pat=Q.front();
  37. Q.pop();
  38. for(int i=0;i<par[teme].size();i++)
  39. {
  40. int sosed=par[teme][i];
  41. if(!v[sosed] && pat>0)
  42. {
  43. Q.push(sosed);
  44. Q.push(pat-1);
  45. v[sosed]=true;
  46. }
  47. }
  48. }
  49. for(int i=0;i<a;i++)
  50. {
  51. if(!v[i])
  52. {
  53. k++;
  54. }
  55. }
  56. cout<<k;
  57. return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement