计蒜客 Fantastic Graph

"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

题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

#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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值