"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 30 test cases.

For each test case,The first line contains three integers N the number of left part graph vertices, M the number of right part graph vertices, and K the number of edges ( 1≤N≤2000,0≤M≤2000,0≤K≤6000). Vertices are numbered from 1 to N.

The second line contains two numbers L,R(0≤L≤R≤300). The two fantastic numbers.

Then K lines follows, each line containing two numbers U, V (1≤U≤N,1≤V≤M). It shows that there is a directed edge from U-th spot to V-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

题意

一个二分图,左边N个点,右边M个点,中间K条边,问你是否可以删掉边使得所有点的度数在[L,R]之间

题解

比赛的时候写的网络流A的,赛后把自己hack了。。

然后写了个贪心,发现还是贪心好写(雾)

考虑两个集合A和B,A为L<=d[i]<=R,B为d[i]>R

枚举每个边

1.如果u和v都在B集合,直接删掉
2.如果u和v都在A集合,无所谓
3.如果u在B,v在A,并且v可删边即d[v]>L
4.如果u在A,v在B,并且u可删边即d[u]>L

最后枚举N+M个点判断是否在[L,R]之间

这个做法虽然不是官方做法,如果有hack的数据可以发评论

最后贴个官方做法,有源汇上下界网络流

代码

 #include<bits/stdc++.h>
using namespace std; const int maxn=; int main()
{
int N,M,K,L,R,o=,u[maxn],v[maxn],d[maxn];
while(scanf("%d%d%d",&N,&M,&K)!=EOF)
{
memset(d,,sizeof d);
scanf("%d%d",&L,&R);
int sum=,flag=;
for(int i=;i<K;i++)
{
scanf("%d%d",&u[i],&v[i]);v[i]+=N;
d[u[i]]++,d[v[i]]++;
}
for(int i=;i<K;i++)
{
int uu=u[i],vv=v[i];
if(d[uu]>R&&d[vv]>R)d[uu]--,d[vv]--;
else if(L<=d[uu]&&d[uu]<=R&&L<=d[vv]&&d[vv]<=R)continue;
else if(L+<=d[uu]&&d[uu]<=R&&d[vv]>R)d[uu]--,d[vv]--;
else if(d[uu]>R&&L+<=d[vv]&&d[vv]<=R)d[uu]--,d[vv]--;
}
for(int i=;i<=N+M;i++)if(d[i]<L||d[i]>R)flag=;
printf("Case %d: %s\n",o++,flag?"Yes":"No");
}
return ;
}

给一点测试数据,网上有的贪心过不去这些数据Yes Yes Yes Yes No


 官方做法

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int maxn=1e5+;
const int maxm=2e5+;
const int INF=0x3f3f3f3f; int TO[maxm],CAP[maxm],NEXT[maxm],tote;
int FIR[maxn],gap[maxn],cur[maxn],d[maxn],q[];
int n,m,S,T; void add(int u,int v,int cap)
{
//printf("i=%d u=%d v=%d cap=%d\n",tote,u,v,cap);
TO[tote]=v;
CAP[tote]=cap;
NEXT[tote]=FIR[u];
FIR[u]=tote++; TO[tote]=u;
CAP[tote]=;
NEXT[tote]=FIR[v];
FIR[v]=tote++;
}
void bfs()
{
memset(gap,,sizeof gap);
memset(d,,sizeof d);
++gap[d[T]=];
for(int i=;i<=n;++i)cur[i]=FIR[i];
int head=,tail=;
q[]=T;
while(head<=tail)
{
int u=q[head++];
for(int v=FIR[u];v!=-;v=NEXT[v])
if(!d[TO[v]])
++gap[d[TO[v]]=d[u]+],q[++tail]=TO[v];
}
}
int dfs(int u,int fl)
{
if(u==T)return fl;
int flow=;
for(int &v=cur[u];v!=-;v=NEXT[v])
if(CAP[v]&&d[u]==d[TO[v]]+)
{
int Min=dfs(TO[v],min(fl,CAP[v]));
flow+=Min,fl-=Min,CAP[v]-=Min,CAP[v^]+=Min;
if(!fl)return flow;
}
if(!(--gap[d[u]]))d[S]=n+;
++gap[++d[u]],cur[u]=FIR[u];
return flow;
}
int ISAP()
{
bfs();
int ret=;
while(d[S]<=n)ret+=dfs(S,INF);
return ret;
} int ca,N,M,Q,x,y,z,l[][],r[][];
char op[]; void init()
{
tote=;
memset(FIR,-,sizeof FIR);
}
int main()
{
int N,M,C,L,R,u,v,s,t,ca=;
while(scanf("%d%d%d",&N,&M,&C)!=EOF)
{
init();
int in[]={};
s=N+M+,t=s+,S=t+,T=S+,n=T;
add(t,s,INF);
scanf("%d%d",&L,&R);
for(int i=;i<C;i++)
{
scanf("%d%d",&u,&v);
add(u,N+v,);
}
for(int i=;i<=N;i++)
{
add(s,i,R-L);
in[s]-=L;
in[i]+=L;
}
for(int i=;i<=M;i++)
{
add(i+N,t,R-L);
in[i+N]-=L;
in[t]+=L;
}
int sum=;
for(int i=;i<=N+M+;i++)
{
if(in[i]>)
{
add(S,i,in[i]);
sum+=in[i];
}
else
add(i,T,-in[i]);
}
printf("Case %d: %s\n",ca++,sum==ISAP()?"Yes":"No");
}
return ;
}

ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心或有源汇上下界网络流)的更多相关文章

  1. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

  2. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (上下界网络流)

    正解: #include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN=1 ...

  3. ACM-ICPC 2018 沈阳赛区网络预赛 F Fantastic Graph(贪心或有源汇上下界网络流)

    https://nanti.jisuanke.com/t/31447 题意 一个二分图,左边N个点,右边M个点,中间K条边,问你是否可以删掉边使得所有点的度数在[L,R]之间 分析 最大流不太会.. ...

  4. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph(有源上下界最大流 模板)

    关于有源上下界最大流: https://blog.csdn.net/regina8023/article/details/45815023 #include<cstdio> #includ ...

  5. Fantastic Graph 2018 沈阳赛区网络预赛 F题

    题意: 二分图 有k条边,我们去选择其中的几条 每选中一条那么此条边的u 和 v的度数就+1,最后使得所有点的度数都在[l, r]这个区间内 , 这就相当于 边流入1,流出1,最后使流量平衡 解析: ...

  6. ACM-ICPC 2018 沈阳赛区网络预赛-D:Made In Heaven(K短路+A*模板)

    Made In Heaven One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. ...

  7. 图上两点之间的第k最短路径的长度 ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven

    131072K   One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. Howe ...

  8. ACM-ICPC 2018 沈阳赛区网络预赛 K Supreme Number(规律)

    https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集 ...

  9. ACM-ICPC 2018 沈阳赛区网络预赛-K:Supreme Number

    Supreme Number A prime number (or a prime) is a natural number greater than 11 that cannot be formed ...

随机推荐

  1. PHP中汉字截取

    $len = 19; $text = "怎么将新闻的很长的标题只显示前面一些字,后面用.....来代替?"; echo strlen($text)<=$len ? $text ...

  2. putty登录显示IP

    登陆服务器 cd vi .bashrc 在尾部加入如下代码 if [ "$SSH_CONNECTION" != '' -a "$TERM" != 'linux' ...

  3. Windows系统封装总结

    注:使用虚拟机或者实体机进行封装均可,实体机进行封装的成功率更高.虚拟机进行封装建议使用VMware,12版本.过高的版本容易造成封装失败 一.            Windows 10系统封装 1 ...

  4. C语言函数入参压栈顺序为什么是从右向左?

    看到有人提问到,在处理printf/cout时,压栈顺序是什么样的?大家都知道是从右往左,也就是说从右往左的计算,但是,这里的计算不等于输出. a++和++a的压栈的区别:在计算时,遇到a++会记录此 ...

  5. [Shell]Bash基本功能:通配符与特殊符号

    /*------------------------------------------------------------------------------------------- @黑眼诗人 ...

  6. 一秒去除Win7快捷方式箭头

    我相信有无数的小盆友跟我一样很讨厌Win7快捷方式图标上的箭头,实在太丑陋了,尤其是带有强迫症滴.现在介绍去除箭头的方式. 1. 打开编辑器,将以下代码粘贴进去,然后保存为.bat后缀的文件,然后双击 ...

  7. app开发中读取数据库信息的vue页面

    <template> <!-- 容器 --> <div class="container"> <!-- 标头 --> <div ...

  8. GankApp 侧滑和title修改颜色的完整项目app

    GankApp 侧滑和title修改颜色的完整项目app GankApp 侧滑和title修改颜色的完整项目app,本项目主要由侧滑框架和4.4以及以上的头部title颜色调整和, 首页viewpag ...

  9. Oracle 导入大量数据

    环境是这样的: 需要导入大量数据到Oracle,目前Oracle已建立索引和触发器了,导入的数据是树型结构,需要关联. 采用的方法是: 删除以前数据库的索引和触发器,用OracleBulkCopy批量 ...

  10. 吴裕雄 python神经网络(6)

    import randomimport numpy as npnp.random.randint(0,49,3) ##required libarariesimport tensorflow as t ...