Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <queue>
  4. using namespace std;
  5. ifstream in("arbore.in");
  6. ofstream out("arbore.out");
  7. queue <int> coada;
  8. int a[101][101],f[101],v[101];
  9. int main()
  10. {
  11. int n,k,x,y,i;
  12. in>>n>>k;
  13. for(i=1;i<n;i++)
  14. {
  15. in>>x>>y;
  16. a[x][y]=1;
  17. a[y][x]=1;
  18. }
  19. coada.push(k);
  20. f[k]--;
  21. while(coada.empty()==false)
  22. {
  23. x=coada.front();
  24. for(i=1;i<=n;i++)
  25. if(a[x][i]==1 && f[i]==0)
  26. {
  27. coada.push(i);
  28. v[i]=x;
  29. f[i]--;
  30. }
  31. coada.pop();
  32. }
  33. for(i=1;i<=n;i++)
  34. out<<v[i]<<" ";
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement