分析
从1道m进行匹配,找到第一个不能继续匹配的点即可
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int n,m,g[1100][1100],used[1100],T,wh[1100],ans[1100],Ans;
inline bool work(int x){
int i,j,k;
for(i=1;i<=n;i++)
if(g[x][i]&&used[i]!=T){
used[i]=T;
if(!wh[i]||work(wh[i])){
wh[i]=x;
ans[x]=i;
return 1;
}
}
return 0;
}
inline void go(){
int i,j,k;
for(i=1;i<=m;i++){
++T;
if(work(i))Ans++;
else return;
}
}
int main(){
int i,j,k;
scanf("%d%d",&n,&m);
for(i=1;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
x++,y++;
g[i][x]=g[i][y]=1;
}
go();
printf("%d\n",Ans);
for(i=1;i<=Ans;i++)printf("%d\n",ans[i]-1);
return 0;
}