Advertisement
a53

ComponenteConexe3

a53
Dec 19th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. using namespace std;
  4. ifstream f("componenteconexe3.in");
  5. ofstream g("componenteconexe3.out");
  6. int a[101][101],n,m,p[101],x[101],lmax,smax[101];
  7. void citire()
  8. {
  9. int x,y;
  10. f>>n;
  11. while(f>>x>>y)
  12. a[x][y]=a[y][x]=1;
  13. }
  14.  
  15. void BF(int k)
  16. {
  17. int s,d,i;
  18. x[1]=k;
  19. p[k]=1;
  20. s=1;
  21. d=1;
  22. while(s<=d)
  23. {
  24. for(i=1;i<=n;++i)
  25. if(a[x[s]][i]==1&&!p[i])
  26. ++d,x[d]=i,p[i]=1;
  27. ++s;
  28. }
  29. if(d>lmax)
  30. {
  31. lmax=d;
  32. for(i=1;i<=lmax;++i)
  33. smax[i]=x[i];
  34. }
  35.  
  36. }
  37.  
  38. int main()
  39. {
  40. citire();
  41. for(int i=1;i<=n;++i)
  42. if(!p[i])
  43. BF(i);
  44. sort(smax+1,smax+lmax+1);
  45. g<<smax[1]<<' '<<lmax;
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement