Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- using namespace std;
- ifstream f("componenteconexe3.in");
- ofstream g("componenteconexe3.out");
- int a[101][101],n,m,p[101],x[101],lmax,smax[101];
- void citire()
- {
- int x,y;
- f>>n;
- while(f>>x>>y)
- a[x][y]=a[y][x]=1;
- }
- void BF(int k)
- {
- int s,d,i;
- x[1]=k;
- p[k]=1;
- s=1;
- d=1;
- while(s<=d)
- {
- for(i=1;i<=n;++i)
- if(a[x[s]][i]==1&&!p[i])
- ++d,x[d]=i,p[i]=1;
- ++s;
- }
- if(d>lmax)
- {
- lmax=d;
- for(i=1;i<=lmax;++i)
- smax[i]=x[i];
- }
- }
- int main()
- {
- citire();
- for(int i=1;i<=n;++i)
- if(!p[i])
- BF(i);
- sort(smax+1,smax+lmax+1);
- g<<smax[1]<<' '<<lmax;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement