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

本文探讨了如何通过选择特定边使二分图中所有顶点的度数落在指定区间内的算法挑战。通过DFS深度优先搜索策略,文章提供了一种解决方案,确保最终图形满足条件,实现了从普通二分图到奇幻图形的转变。

"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 }

 

转载于:https://www.cnblogs.com/tingtin/p/9610097.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值