1. 程式人生 > >ACM-ICPC 2018 沈陽賽區網絡預賽 F. Fantastic Graph

ACM-ICPC 2018 沈陽賽區網絡預賽 F. Fantastic Graph

scan and otto tps print href -i cto content

"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,R (0 \le L \le R \le 300)(0LR300). 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)(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 }

ACM-ICPC 2018 沈陽賽區網絡預賽 F. Fantastic Graph