Advertisement
Guest User

Untitled

a guest
Dec 21st, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include<fstream>
  3. #include<vector>
  4. #include<deque>
  5. using namespace std;
  6. vector<int> v[11];
  7. void addedge();
  8. int main(){
  9. int cont=0;
  10. int visitato[11];
  11. for(int i=0;i<11;i++)
  12. visitato[i]=0;
  13. addedge();
  14. deque<int> d;
  15. d.push_back(0);
  16. int corrente=0;
  17. int nododaraggiungere;
  18. cin>>nododaraggiungere;
  19. int r=0;
  20. int u=1;
  21. while(d.size()!=0&&corrente!=nododaraggiungere){
  22. corrente=d[0];
  23. d.pop_front();
  24. if(visitato[corrente]==0){
  25. r++;
  26. visitato[corrente]=1;
  27. for(auto i:v[corrente]){
  28. if(visitato[i]==0)
  29. d.push_back(i);
  30. }
  31. }
  32. if(r>=u&&corrente!=nododaraggiungere){
  33. cont++;
  34. r=0;
  35. u=d.size();
  36. }
  37. }
  38. cout<<endl<<cont;
  39. return 0;
  40. }
  41.  
  42. void addedge(){
  43. v[0].push_back(1);
  44. v[0].push_back(2);
  45. v[2].push_back(0);
  46. v[1].push_back(0);
  47. v[1].push_back(3);
  48. v[3].push_back(1);
  49. v[2].push_back(6);
  50. v[2].push_back(5);
  51. v[2].push_back(4);
  52. v[4].push_back(2);
  53. v[5].push_back(2);
  54. v[6].push_back(2);
  55. v[3].push_back(7);
  56. v[3].push_back(8);
  57. v[3].push_back(9);
  58. v[7].push_back(3);
  59. v[8].push_back(3);
  60. v[9].push_back(3);
  61. v[5].push_back(10);
  62. v[10].push_back(5);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement