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

题目来源

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

时间: 2024-11-08 01:09:57

ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph的相关文章

ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心)

分析:贪心地删边后检查每个点的度即可,这也是正确的做法? #include <bits/stdc++.h> using namespace std; const int MAXN = 1e4+5; struct Edge{ int u,v,next; }edges[MAXN<<2]; int head[MAXN],tot; int deg[MAXN]; void init() { memset(head,-1,sizeof(head)); tot =0 ; memset(deg,0

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

A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying two smaller natural numbers. Now lets define a number NN as the supreme number if and only if each number made up of an non-empty subsequence of all

【ACM-ICPC 2018 沈阳赛区网络预赛 I】Lattice&#39;s basics in digital electronics

[链接] 我是链接,点我呀:) [题意] 每个单词的前缀都不同. 不能更明示了... 裸的字典树. 模拟一下.输出一下就ojbk了. [题解] #include <bits/stdc++.h> #define LL long long #define rep1(i,a,b) for (int i = a;i <= b;i++) #define rep2(i,a,b) for (int i = a;i >= b;i--) #define all(x) x.begin(),x.end(

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

A. Gudako and Ritsuka 留坑 B. Call of Accepted 留坑 C. Convex Hull 留坑 D. Made In Heaven 留坑 E. The cake is a lie 留坑 F. Fantastic Graph 留坑 G. Spare Tire 留坑 H. Hamming Weight 留坑 I. Lattice's basics in digital electronics 留坑 J. Ka Chang 留坑 K. Supreme Number

Made In Heaven 2018 沈阳赛区网络预赛 D题

求第k短路 模板题 套模板即可 #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <queue> using namespace std; const int maxn=1005; const int maxe=100005; struct State{ int f; // f=g+dis dis表示当前点到终点的最短路径,即之前的

ACM-ICPC 2018 沈阳赛区网络预赛-I模拟题啊!!!

垃圾题,题目巨TM长...这题题意就是说给你一个16进制串,让你把每一位转成长度为4的2进制数,并把这些数连接起来,连接完成后,进行奇偶校验,把字符串切割成每个长度为9的字符串,然后计算前8位的 1的个数,,最后一位是校验位,如果1的个数为奇数 那么校验位应该是1,如果1的个数为偶数,那么校验位应该是0,如果满足,就保留验证的8位去掉校验位,否则去掉整个:然后给了M个字符串对应的ASCll,把验证位置留下来的东西,进行和字符串匹配,然后输出N个对应ASCll的字符??? 这题意很绕啊...不过纯

ACM-ICPC 2018 沈阳赛区网络预赛 Made In Heaven(K短路)题解

思路:K短路裸题 代码: #include<queue> #include<cstring> #include<set> #include<map> #include<stack> #include<string> #include<cmath> #include<vector> #include<cstdio> #include<iostream> #include<algori

ACM-ICPC 2018 沈阳赛区网络预赛 J. Ka Chang(树上分块+dfs序+线段树)

题意 链接:https://nanti.jisuanke.com/t/A1998 给出一个有根树(根是1),有n个结点.初始的时候每个结点的值都是0.下面有q个操作,操作有两种,操作1.将深度为L(根节点深度为0)的点的值全部增加X.操作2.查询以x为根的子树的结点值得和.其中N,Q<=1e5. 思路 因为这题是对某一深度的所有点加x,所以不是树链剖分. 我们可以先预处理一下dfs序,顺带把d[u]:u的深度.dd[x]:深度为x的点集求出来. 考虑分块,对某一深度分两种情况:1.这一深度的点的

ACM-ICPC 2018 沈阳赛区网络预赛 G. Spare Tire

这题很好啊,好在我没做出来...大概分析了一下,题目大概意思就是求 问所有满足1<=i<=n且i与m互素的ai之和 最开始我们队的做法是类似线性筛的方法去筛所有数,把数筛出来后剩下数即可,但是这样的是时间复杂度十分大,我们需要遍历每个质因 的倍数,这样最坏的复杂度是很大的1e8,因为我们需要把i的倍数筛到1e8,这样肯定不行,那么想想其他办法 我们想到了容斥-----(赛后想到的) 我们可以推处一个公式ai=i*i+i; 那么ai的前n项和Tn=n*(n+1)*(2*n+1)/6+n*(n+1