http://www.lydsy.com/JudgeOnline/problem.php?id=1191 (Topic link)
Test instructions: There are m problems, n an ace, each can solve a problem, each problem has two tricks can be solved, the maximum can solve a few problems.
Solution
Bare binary graph matching. The M problem is regarded as a set of nodes, and N is considered as a set of nodes, and the maximum match is obtained. Note that when a problem is answered and the game ends directly, find returns to 0 o'clock break.
Code:
bzoj1191 #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> # include<cstdio> #include <cmath> #define LL long long #define INF 2147483640 #define PI 3.1415926535898 #define
Free (a) freopen (a ".", "R", stdin), Freopen (a ". Out", "w", stdout);
using namespace Std;
const int maxn=1010; struct Edge {int to,next;}
e[maxn<<2];
int f[maxn][maxn],vis[maxn],head[maxn],p[maxn],cnt,n,m;
BOOL Find (int x) {for (int i=head[x];i;i=e[i].next) if (!vis[e[i].to]) {vis[e[i].to]=1;
if (p[e[i].to]==0 | | | find (P[E[I].TO])) {p[e[i].to]=x;
return 1;
}}/* for (int i=0;i<n;i++) if (F[x][i] &&!vis[i]) {vis[i]=1;
if (p[i]==0 | | | find (p[i])) {p[i]=x;
return 1;
}} */return 0; } void Insert (int u,int v) {e[++cnt].to=v;e[cnt].next=head[u];head[u]=cnt;} int Main () {scanf ("%d%d", &n,&m);
cnt=0;
for (int i=1;i<=m;i++) {int x, y;
scanf ("%d%d", &x,&y);
Insert (i,x); insert (i,y);
F[i][x]=f[i][y]=1;
} int ans=0;
for (int i=1;i<=m;i++) {for (int j=0;j<=n;j++) vis[j]=0;
if (find (i)) ans++;
else break;
} printf ("%d", ans);
return 0; }