1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Const intmaxn=1001+ -;7 intP[MAXN][MAXN];8 intVIS[MAXN],LK[MAXN];9 intn,m;Ten One voidInit () A { -scanf"%d%d",&n,&m); - for(intI=1; i<=m;i++) the { - intu,v; -scanf"%d%d",&u,&v); -p[i][u]=p[i][v]=1; + } - } + A intFindintu) at { - for(intI=0; i<n;i++) - { - if(!vis[i] &&P[u][i]) - { -vis[i]=1; in if(!lk[i] | |find (Lk[i])) - { tolk[i]=u; + return 1; - } the } * } $ return 0;Panax Notoginseng } - the voidHungary () + { Amemset (LK,0,sizeof(LK)); the intans=0; + for(intI=1; i<=m;i++) - { $memset (Vis,0,sizeof(Vis)); $ if(Find (i)) ans++;Else Break; - /*I first wrote the IF (!find (i)) output i-1 and break: Later found that if all the questions can be answered, there is no output*/ - } thecout<<ans<<Endl; - }Wuyi the intMain () - { Wu init (); - Hungary (); About return 0; $}
"Hungarian algorithm template" bzoj1191-superhero