"Oh, There is a bipartite graph.""Make it Fantastic."
X wants to check whether a bipartite graph is a fantastic graph. He has two fantastic numbers, and he wants to let all the degrees to between the two boundaries. You can pick up several edges from the current graph and try to make the degrees of every point to between the two boundaries. If you pick one edge, the degrees of two end points will both increase by one. Can you help X to check whether it is possible to fix the graph?
Input
There are at most 3030 test cases.
For each test case,The first line contains three integers NN the number of left part graph vertices, MM the number of right part graph vertices, and KK the number of edges ( 1 \le N \le 20001≤N≤2000,0 \le M \le 20000≤M≤2000,0 \le K \le 60000≤K≤6000 ). Vertices are numbered from 11 to NN.
The second line contains two numbers L, RL,R (0 \le L \le R \le 300)(0≤L≤R≤300). The two fantastic numbers.
Then KK lines follows, each line containing two numbers UU, VV (1 \le U \le N,1 \le V \le M)(1≤U≤N,1≤V≤M). It shows that there is a directed edge from UU-th spot to VV-th spot.
Note. There may be multiple edges between two vertices.
Output
One line containing a sentence. Begin with the case number. If it is possible to pick some edges to make the graph fantastic, output "Yes"
(without quote), else output "No"
(without quote).
样例输入复制
3 3 7 2 3 1 2 2 3 1 3 3 2 3 3 2 1 2 1 3 3 7 3 4 1 2 2 3 1 3 3 2 3 3 2 1 2 1
样例输出复制
Case 1: Yes Case 2: No
题目来源
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lowbit(x) x&(-x)
typedef pair<int,int>pa;
const int maxn=6050;
int u[maxn],v[maxn],dis[maxn];
int n,m,k,l,r;
int main()
{
int cas=1,flag=0;
while(scanf("%d %d %d",&n,&m,&k)!=EOF)
{
flag=1;
memset(dis,0,sizeof(dis));
scanf("%d %d",&l,&r);
for(int i=1;i<=k;i++)
{
scanf("%d %d",&u[i],&v[i]);
v[i]+=n;
dis[u[i]]++;
dis[v[i]]++;
}
for(int i=1;i<=k;i++)
{
int uu=u[i],vv=v[i];
if(dis[uu]>r&&dis[vv]>r)
{
dis[uu]--;
dis[vv]--;
}
else if(dis[uu]>=l&&dis[uu]<=r&&dis[vv]>=l&&dis[vv]<=r)
{
continue;
}
else if(dis[uu]>=l+1&&dis[uu]<=r&&dis[vv]>r)
{
dis[uu]--;
dis[vv]--;
}
else if(dis[uu]>r&&dis[vv]>=l+1&&dis[vv]<=r)
{
dis[uu]--;
dis[vv]--;
}
}
for(int i=1;i<=n+m;i++)
{
if(dis[i]<l||dis[i]>r)
{
flag=0;
break;
}
}
printf("Case %d: %s\n",cas++,flag?"Yes":"No");
}
return 0;
}