本来想打场uoj的,看到数论又跪了。。
还是二分图
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 #define inc(i,l,r) for(i=l;i<=r;i++) 3 #define dec(i,l,r) for(i=l;i>=r;i--) 4 #define mem(a) memset(a,0,sizeof(a)) 5 #define inf 1e9 6 #define ll long long 7 #define succ(x) (1<<x) 8 #define NM 2000+5 9 using namespace std; 10 int read(){ 11 int x=0,f=1;char ch=getchar(); 12 while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} 13 while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); 14 return x*f; 15 } 16 struct edge{ 17 int t; 18 edge *next; 19 }e[2*NM],*h[NM]; 20 int n,m,i,t,k,v[NM],match[NM],s; 21 void add(int x,int y){ 22 e[++s].t=y;e[s].next=h[x];h[x]=e+s; 23 } 24 bool dfs(int x){ 25 for(edge *j=h[x];j;j=j->next) 26 if(v[j->t]!=i){ 27 v[j->t]=i; 28 if(!match[j->t]||dfs(match[j->t])){ 29 match[j->t]=x; 30 return true; 31 } 32 } 33 return false; 34 } 35 int main(){ 36 m=read();n=read(); 37 inc(i,1,n) 38 inc(k,1,2){ 39 t=read(); 40 add(i,n+t+1); 41 } 42 inc(i,1,n) 43 if(!dfs(i))break; 44 printf("%d\n",i-1); 45 return 0; 46 }