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 20001N2000,0 \le M \le 20000M2000,0 \le K \le 60000K6000 ). Vertices are numbered from 11 to NN.

The second line contains two numbers L, RL,(0 \le L \le R \le 300)(0LR300). The two fantastic numbers.

Then KK lines follows, each line containing two numbers UU, V(1 \le U \le N,1 \le V \le M)(1UN,1VM). 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 沈阳赛区网络预赛

 

 

 

一个二分图,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 }
复制代码

 

posted on   cltt  阅读(838)  评论(1编辑  收藏  举报

编辑推荐:
· 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框架的用法!
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示