Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4. ifstream f ("lant1.in");
  5. ofstream g ("lant1.out");
  6. int n,p,l,pr,u,q,r,x,y,nr,i,c[101],viz[101],t[101],a[101][101];
  7. void lant (int x)
  8. {if (t[x])
  9. {lant(t[x]);
  10. g<<x<<" ";
  11. }
  12. }
  13. int main()
  14. {f>>n>>p>>q>>r;
  15. while (f>>x>>y)
  16. {
  17. a[x][y]=a[y][x]=1;
  18. }
  19. pr=1;
  20. u=1;
  21. c[pr]=r;
  22. viz[r]=1;
  23. t[r]=0;
  24. while (pr<=u)
  25. {x=c[pr];
  26. ++pr;
  27. for (i=1;i<=n;++i)
  28. if (a[i][x]==1&&viz[i]==0)
  29. {++u;
  30. c[u]=i;
  31. viz[i]=viz[x]+1;
  32. t[i]=x;
  33. }
  34. }
  35. g<<viz[q]+viz[p]-1<<'\n';
  36. x=p;
  37. while (x!=0)
  38. {g<<x<<" ";
  39. x=t[x];
  40. }
  41. lant(q);
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement