#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e4+10;
vector<int>a[N];
int f[N];
int n,m;
int f3=0;
int r,wr;
int ans=0;
void dfs(int x){
for(int i:a[x]){
if(f[i]==f[x]){
f3++;
return ;
}
if(f[i]==0){
f[i]=3-f[x];
if(f[i]==1){
r++;
}
else{
wr++;
}
dfs(i);
if(f3>0){
return;
}
}
}
return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m;
int x,y;
for(int i=1;i<=m;i++){
cin>>x>>y;
a[x].push_back(y);
a[y].push_back(x);
}
for(int i=1;i<=n;i++){
if(f[i]==0){
f[i]++;
r=1;
wr=0;
f3=0;
dfs(i);
if(f3==0){
ans+=min(r,wr);
}
else{
cout<<"Impossible"<<endl;
return 0;
}
}
}
cout<<ans<<endl;
}
P1330 封锁阳光大学
最新推荐文章于 2024-08-07 14:10:19 发布