2018 icpc区域赛沈阳赛区网络赛F题 (一道不需要网络流的网络流题)

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

附上题目链接:https://nanti.jisuanke.com/t/31447

给出一个二分图,所有点的编号是1~n,然后给出k条路,左边向右边连边,问能否删除一些边(也可以不删除)使得每个点的度数,在给的(l,r)范围之内。实在想不到这个题需要用网络流来求解,可能是数据太水了吧。

我当时做这个题的时候,直接记录了所有点的度数,判断每个点的度数是否小于l,因为度数大于r,可以删边,但是小于l,就直接NO可以了。

我是从51nod上的一道二分图的题受到的启发。

https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1397,稍后我也会发一个题解。

 

#pragma GCC optimize(2)
#include
#include
#include
#include
using namespace std;
const int maxn = 4500;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int n, m, k;
int l, r;
int _case = 1;
int ru[maxn], c[maxn];
void init(int N)
{
	for (int i = 0; i <= N; i++)
	{
		ru[i] = 0;
		c[i] = 0;
	}
}
int main()
{
	//freopen("C://input.txt", "r", stdin);
	while (scanf("%d%d%d", &n, &m, &k) != EOF)
	{
		int flag = 1;
		scanf("%d%d", &l, &r);
		init(n+m);
		for (int i = 1; i <= k; i++)
		{
			int u, v;
			scanf("%d%d", &u, &v);
			c[u]++;
			ru[v + n]++;
		}
		for (int i = 1; i <= n + m; i++)
		{
			if (c[i] + ru[i] < l)
			{
				flag = 0;
			}
		}
		if (flag == 1)
		{
			printf("Case %d: Yes\n", _case++);
		}
		else
		{
			printf("Case %d: No\n", _case++);
		}
	}
	return 0;
}

 

你可能感兴趣的:(网络流)