1362:家庭问题(family)
图似乎早早地来了!┭┮﹏┭┮
1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 using namespace std; 5 const int N=105; 6 int n,k,ans,maxx,vis[N],a[N][N]; 7 queue<int> q; 8 void solve(int x){ 9 q.push(x); 10 ans++;vis[x]=1; 11 int cnt=0; 12 while(!q.empty()){ 13 int x=q.front(); 14 q.pop(); 15 for(int i=1;i<=n;i++){ 16 if(i!=x&&a[x][i]&&!vis[i]){ 17 vis[i]=1; 18 q.push(i); 19 cnt++; 20 } 21 } 22 } 23 maxx=max(maxx,cnt+1); 24 } 25 int main(){ 26 cin>>n>>k; 27 int x,y; 28 for(int i=1;i<=k;i++){ 29 scanf("%d%d",&x,&y); 30 a[x][y]=a[y][x]=1; 31 } 32 for(int i=1;i<=n;i++) 33 if(!vis[i])solve(i); 34 cout<<ans<<" "<<maxx; 35 return 0; 36 }