ACM-ICPC 2018 沈阳赛区网络预赛 F. 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
题目来源
一个二分图,M条边,选用M条边的一些,令最后所有点的度数都在[l,r]内 ,可以Yes 否则 No
1 #include <iostream> 2 #include <vector> 3 #include <cstdio> 4 #include <cstring> 5 using namespace std; 6 #define P pair<int,int> 7 #define ph push_back 8 #define ll long long 9 #define M 4400 10 #define fi first 11 #define se second 12 vector<P>ve[M]; 13 int num[M],e[M]; 14 int n,m,k,l,r; 15 void dfs(int sta,int maxx) 16 { 17 for(int i=0;i<ve[sta].size();i++){ 18 P p=ve[sta][i]; 19 if(!e[p.se]){ 20 e[p.se]=1; 21 if(num[p.fi]<maxx&&num[sta]<maxx){//遍历所有的边,在maxx的范围内,尽量用边 22 num[p.fi]++; 23 num[sta]++; 24 dfs(p.fi,maxx); 25 } 26 } 27 } 28 } 29 void init() 30 { 31 for(int i=1;i<=n+m;i++) 32 { 33 num[i]=0; 34 e[i]=0; 35 ve[i].clear(); 36 } 37 } 38 int main() 39 { 40 int cnt=0; 41 while(~scanf("%d%d%d",&n,&m,&k)){ 42 init(); 43 scanf("%d%d",&l,&r); 44 int x,y; 45 for(int i=0;i<k;i++) 46 { 47 scanf("%d%d",&x,&y); 48 ve[x].ph({y+n,i}); 49 ve[y+n].ph({x,i}); 50 } 51 dfs(1,r); 52 int flag=1; 53 for(int i=1;i<=n+m;i++) 54 { 55 if(num[i]<l) {//如果最后还有点的度数不满足条件,就No 56 flag=0; 57 break; 58 } 59 } 60 printf("Case %d: ",++cnt); 61 printf("%s\n",flag?"Yes":"No"); 62 } 63 return 0; 64 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!