Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. vector<int>v[100005];
  4. vector<int>a[100008];
  5. queue<int>q;
  6. int z,color[100008];
  7. void bfs(int source)
  8. {
  9. int i,level=1,u;
  10. a[level].push_back(source);
  11. color[source]=1;
  12. q.push(source);
  13. level++;
  14. while(!q.empty())
  15. {
  16. u=q.front();
  17. q.pop();
  18. for(i=0;i<v[u].size();i++)
  19. {
  20. if(color[v[u][i]]==0)
  21. {
  22. q.push(v[u][i]);
  23. color[v[u][i]]=1;
  24. a[level].push_back(v[u][i]);
  25. }
  26. }
  27. level++;
  28. }
  29.  
  30.  
  31. }
  32. int main()
  33. {
  34. int n,i,x,y;
  35. scanf("%d",&n);
  36. for(i=1;i<=n-1;i++)
  37. {
  38. scanf("%d %d",&x,&y);
  39. v[x].push_back(y);
  40. v[y].push_back(x);
  41. }
  42. scanf("%d",&z);
  43. bfs(1);
  44. printf("%d\n",a[z].size());
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement