Problem 1124 - Football Coach

Description
It is not an easy job to be a coach of a football team. The season is almost over, only a few matches are left to play. All of sudden the team 
manager comes to you and tells you bad news: the main sponsor of your club is not happy with your results and decided to stop sponsoring your 
team, which probably means the end of your club. The sponsor's decision is final and there is no way to change it unless... unless your team 
miraculously wins the league. 
The manager left you in deep thought. If you increase the number of practices and offer players a generous bonus for each match, you may be 
able to win all the remaining matches. Is that enough? You also have to make sure that teams with many points lose against teams with few 
points so that in the end, your team will have more points than any other team. You know some of the referees and can bribe them to manipulate 
the result of each match. But first you need to figure out how to manipulate the results and whether it is possible at all. 
There are N teams numbered 1 through N, your team has the number N. The current number of points of each team and the list of remaining 
matches are given. Your task is to find out whether it is possible to manipulate each remaining match so that the team N will finish with 
strictly more points than any other team. If it is possible, output "YES", otherwise, output "NO". In every match, the winning team gets 2 
points, the losing team gets 0. If the match ends with a draw, both teams get 1 point. 
Input
There will be multiple test cases. Each test case has the following form: The first line contains two numbers N(1 <= N <= 100) and M(0 <= M <= 
1000). The next line contains N numbers separated by spaces giving the current number of points of teams 1, 2, ..., N respectively. The 
following M lines describe the remaining matches. Each line corresponds to one match and contains two numbers a and b (a not equal to b, 1 <= 
a,b <= N) identifying the teams that will play in the given match. There is a blank line after each test case.
Output
For each test case, output "YES" or "NO" to denote whether it's possible to manipulate the remaining matches so that the team N would win 
the league.
Sample Input
5 8
2 1 0 0 1
1 2
3 4
2 3
4 5
3 1
2 4
1 4
3 5
5 4
4 4 1 0 3
1 3
2 3
3 4
4 5
Sample Output
YES
NO
Hint
The problem is so hard that even I have told you the method here is "maximum network flow", you can't solve it. You can have a try, but don?t waste too much time here if you are not perfect at modeling a network.
Source
2006 Team Select Round 3
 
题解:
先将所有和n有关的比赛让n赢
然后再每一场比赛与S相连容量为2
S与有关的队伍相连,容量为2
队伍与T相连容量为Val[n]-Val[i]-1 保证每一个队伍的流量不超过Val[n];
如果流量=2*除去与n有关比赛场数 代表所有的比赛都比完了,且没有一个队伍Val>=Val[n] 输出YES
反之 如果< 除去与n有关比赛场数 代表比赛还没有比完 但如果再流就会导致Val>=Val[n] 输出NO
代码:
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cmath>
  5. #include<cstring>
  6. #include<cstdlib>
  7. using namespace std;
  8. const int N=,M=,INF=;
  9. int n,m,T;
  10. int val[N];
  11. int gi(){
  12. int str=;char ch=getchar();
  13. while(ch>''||ch<'')ch=getchar();
  14. while(ch>='' && ch<='')str=str*+ch-'',ch=getchar();
  15. return str;
  16. }
  17. struct Lin{
  18. int next,to,dis;
  19. }a[M*];
  20. int head[M],num=;
  21. void init(int x,int y,int z){
  22. a[++num].next=head[x];
  23. a[num].to=y;
  24. a[num].dis=z;
  25. head[x]=num;
  26. a[++num].next=head[y];
  27. a[num].to=x;
  28. a[num].dis=;
  29. head[y]=num;
  30. }
  31. int dep[M],q[M],cnt;
  32. bool bfs()
  33. {
  34. memset(dep,,sizeof(dep));
  35. q[]=;dep[]=;
  36. int t=,sum=,x,u;
  37. while(t!=sum)
  38. {
  39. x=q[++t];
  40. for(int i=head[x];i;i=a[i].next){
  41. u=a[i].to;
  42. if(dep[u] || a[i].dis<=)continue;
  43. q[++sum]=u;dep[u]=dep[x]+;
  44. }
  45. }
  46. if(dep[T])return true;
  47. return false;
  48. }
  49. int dfs(int x,int flow)
  50. {
  51. if(x==T || !flow)return flow;
  52. int tot=,u,tmp;
  53. for(int i=head[x];i;i=a[i].next){
  54. u=a[i].to;
  55. if(dep[u]!=dep[x]+ || a[i].dis<=)continue;
  56. tmp=dfs(u,min(flow,a[i].dis));
  57. a[i].dis-=tmp;
  58. a[i^].dis+=tmp;
  59. flow-=tmp;
  60. tot+=tmp;
  61. if(!flow)break;
  62. }
  63. return tot;
  64. }
  65. bool Flow()
  66. {
  67. int tot=,a;
  68. while(bfs()){
  69. a=dfs(,INF);
  70. while(a)tot+=a,a=dfs(,INF);
  71. }
  72. return tot==cnt*;
  73. }
  74. void work()
  75. {
  76. T=n+m;cnt=m;
  77. int x,y;
  78. for(int i=;i<=n;i++)val[i]=gi();
  79. for(int i=;i<=m;i++){
  80. x=gi();y=gi();
  81. if(x==n || y==n)val[n]+=,cnt--;
  82. else{
  83. init(,i,);
  84. init(i,x+m,);init(i,y+m,);
  85. }
  86. }
  87. for(int i=;i<n;i++){
  88. init(i+m,T,val[n]-val[i]-);
  89. }
  90. for(int i=;i<n;i++)if(val[i]>=val[n]){
  91. printf("NO\n");
  92. return ;
  93. }
  94. if(Flow())printf("YES\n");
  95. else printf("NO\n");
  96. }
  97. void Clear()
  98. {
  99. num=;
  100. memset(head,,sizeof(head));
  101. }
  102. int main()
  103. {
  104. while(~scanf("%d%d",&n,&m)){
  105. work();
  106. Clear();
  107. }
  108. }

WOJ 124. Football Coach 网络流的更多相关文章

  1. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  2. May 04th 2017 Week 18th Thursday

    No matter how far you may fly, never forget where you come from. 无论你能飞多远,都别忘了你来自何方. I never forget w ...

  3. listen 60

    Barbie Exposure May Limit Girls' Career Imagination The ubiquitous Barbie doll: she's been everythin ...

  4. 数据结构与算法分析 - 网络流入门(Network Flow)

    转载:网络流基础篇--Edmond-Karp算法             BY纳米黑客 网络流的相关定义: 源点:有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点. 汇点:另一个点也很特殊, ...

  5. 17111 Football team

    时间限制:1000MS  内存限制:65535K 提交次数:0 通过次数:0 题型: 编程题   语言: C++;C Description As every one known, a footbal ...

  6. light oj 1153 - Internet Bandwidth【网络流无向图】

    1153 - Internet Bandwidth   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  7. 数据结构之网络流入门(Network Flow)简单小节

    网络流的相关定义: 源点:有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点. 汇点:另一个点也很特殊,只进不出,叫做汇点. 容量和流量:每条有向边上有两个量,容量和流量,从i到j的容量通常用 ...

  8. 网络流入门—用于最大流的Dinic算法

    "网络流博大精深"-sideman语 一个基本的网络流问题 最早知道网络流的内容便是最大流问题,最大流问题很好理解: 解释一定要通俗! 如右图所示,有一个管道系统,节点{1,2,3 ...

  9. 网络流入门--最大流算法Dicnic 算法

    感谢WHD的大力支持 最早知道网络流的内容便是最大流问题,最大流问题很好理解: 解释一定要通俗! 如右图所示,有一个管道系统,节点{1,2,3,4},有向管道{A,B,C,D,E},即有向图一张.  ...

随机推荐

  1. SaaS的那些事儿

    前两年...   大一大二期间,不知道软件架构.云服务器.数据库为何物,偶尔听过却从未用过.天天学的写的东西都是一些命令行代码,所幸在学完<数据结构>和<算法导论>后能够独立实 ...

  2. 在深度linux下安装pip3与jupyter

    前言 以下安装说明基于已经正确安装python3 文件下载 https://pypi.python.org/pypi/pip 下载pip-9.0.1.tar.gz (md5, pgp)文件 安装准备工 ...

  3. Tornado 网站demo 二

    连接数据库 methods 中建立一个文件 db.py 分别建立起连接对象和游标对象 #!/usr/bin/env Python # coding=utf-8 import pymysql conn ...

  4. Swift 2.2 的新特性

    导读:本文来自SwiftGG翻译组,作者@walkingway基于苹果Swift官方博客中Ted Kremenek所撰写的"Swift 2.2 Released!"文章进行了关于S ...

  5. Codeforces 193 D. Two Segments

    http://codeforces.com/contest/193/problem/D 题意: 给一个1~n的排列,在这个排列中选出两段区间,求使选出的元素排序后构成公差为1的等差数列的方案数. 换个 ...

  6. [Android FrameWork 6.0源码学习] View的重绘过程之WindowManager的addView方法

    博客首页:http://www.cnblogs.com/kezhuang/p/关于Activity的contentView的构建过程,我在我的博客中已经分析过了,不了解的可以去看一下<[Andr ...

  7. vue mint-ui 三级地址联动

    我也是第一次写这种地址联动的 刚开始的时候 我还以为直接用select来写 后来公司的ios告知并不是这样的 他说应该时这样的 于是第一想法 赶紧找插件吧 但是找了一会未果  就问了公司大神 他刚开始 ...

  8. vue style width a href动态拼接问题 ?

    style width 这个问题 折磨了我一个上午了  好惭愧 因为项目涉及到 进度条 所以必须用行内样式  style 用过vue的都知道 vue中style的用法 大众用法 :style=&quo ...

  9. lamp环境搭建经验总结

    环境:centos6.4,13个源码包:参考教程高罗峰细说php思路:1.首先确定gcc,g++的安装,因为这是c语言的编译工具,没有它,源码不可能安装,redhat的yum需要配置,分为本地源和网络 ...

  10. win-zabbix_agent端配置解析

    Zabbix agent 在windows上安装部署 部署windows服务器需要在agent服务器上添加到10.4.200.2的路由 蓝泰服务器需要添加10.0.90.5的网关,联通的机器需要添加到 ...