Advertisement
Guest User

To

a guest
Feb 24th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. ifstream in("dmax.in");
  4. ofstream out("dmax.out");
  5. int a[101][101],n,m,x,y,v[101],c[101];
  6. inline void bfs(int r,int h)
  7. {
  8. register int k,st=1,dr=1;
  9. v[r]=h,c[st]=r;
  10. while(st<=dr)
  11. {
  12. k=c[st];
  13. for(int i=1;i<=n;i++)
  14. if(!v[i] && a[k][i])
  15. v[i]=v[k]+1,c[++dr]=i;
  16. st++;
  17. }
  18. }
  19. inline void citire()
  20. {
  21. in>>n>>m;
  22. while(in>>x>>y)
  23. a[x][y]=a[y][x]=1;
  24. bfs(1,0);
  25. out<<distance(v+1,max_element(v+1,v+n+1))+1;
  26. }
  27. int main()
  28. {
  29. citire();
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement