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
代码:
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
const int N=,M=,INF=;
int n,m,T;
int val[N];
int gi(){
int str=;char ch=getchar();
while(ch>''||ch<'')ch=getchar();
while(ch>='' && ch<='')str=str*+ch-'',ch=getchar();
return str;
}
struct Lin{
int next,to,dis;
}a[M*];
int head[M],num=;
void init(int x,int y,int z){
a[++num].next=head[x];
a[num].to=y;
a[num].dis=z;
head[x]=num;
a[++num].next=head[y];
a[num].to=x;
a[num].dis=;
head[y]=num;
}
int dep[M],q[M],cnt;
bool bfs()
{
memset(dep,,sizeof(dep));
q[]=;dep[]=;
int t=,sum=,x,u;
while(t!=sum)
{
x=q[++t];
for(int i=head[x];i;i=a[i].next){
u=a[i].to;
if(dep[u] || a[i].dis<=)continue;
q[++sum]=u;dep[u]=dep[x]+;
}
}
if(dep[T])return true;
return false;
}
int dfs(int x,int flow)
{
if(x==T || !flow)return flow;
int tot=,u,tmp;
for(int i=head[x];i;i=a[i].next){
u=a[i].to;
if(dep[u]!=dep[x]+ || a[i].dis<=)continue;
tmp=dfs(u,min(flow,a[i].dis));
a[i].dis-=tmp;
a[i^].dis+=tmp;
flow-=tmp;
tot+=tmp;
if(!flow)break;
}
return tot;
}
bool Flow()
{
int tot=,a;
while(bfs()){
a=dfs(,INF);
while(a)tot+=a,a=dfs(,INF);
}
return tot==cnt*;
}
void work()
{
T=n+m;cnt=m;
int x,y;
for(int i=;i<=n;i++)val[i]=gi();
for(int i=;i<=m;i++){
x=gi();y=gi();
if(x==n || y==n)val[n]+=,cnt--;
else{
init(,i,);
init(i,x+m,);init(i,y+m,);
}
}
for(int i=;i<n;i++){
init(i+m,T,val[n]-val[i]-);
}
for(int i=;i<n;i++)if(val[i]>=val[n]){
printf("NO\n");
return ;
}
if(Flow())printf("YES\n");
else printf("NO\n");
}
void Clear()
{
num=;
memset(head,,sizeof(head));
}
int main()
{
while(~scanf("%d%d",&n,&m)){
work();
Clear();
}
}

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. 201621123057 《Java程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 在上一周的总结上做了一点补充 1.2 选做:收集你认为有用的代码片段 2. 书面作业 本次作业题集集合 1. ...

  2. django模板(一)

    模板(一) 实验简介 在前一章中,你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python 代码之中. def current_datetime(req ...

  3. .NET Core装饰模式和.NET Core的Stream

    该文章综合了几本书的内容. 某咖啡店项目的解决方案 某咖啡店供应咖啡, 客户买咖啡的时候可以添加若干调味料, 最后要求算出总价钱. Beverage是所有咖啡饮料的抽象类, 里面的cost方法是抽象的 ...

  4. C语言学习(二)

    今天在程序员面试题中,碰到一个有意思的题目:数组a[N],存放了1至N-1个数,其中某个数重复一次,现在要求找出重复的数字且程序时间复杂度必须为O(N).乍一看,如果不计时间复杂度和空间复杂度程序比较 ...

  5. iOS 封装.framework 以及使用

    .framework是什么? .framework是什么? 这个问题相信做iOS的都知道答案. 在我们的日常开发中,经常会用到各种已经封装好的库,比如支付宝.微信SDK等等中的库,这些库可以给我们的开 ...

  6. 查看eclipse ADT SDK JDK版本号

    一.查看eclipsea版本号: 启动eclipse,Help > About Eclipse SDK,在eclipse SDK对话框下面就有Eclipse SDK Version:4.2.0这 ...

  7. Javascript 判断传入的两个数组是否相似

    任务描述: 请在index.html文件中,编写arraysSimilar函数,实现判断传入的两个数组是否相似.具体需求: 1. 数组中的成员类型相同,顺序可以不同.例如[1, true] 与 [fa ...

  8. @Select注解的情况下,重载的报错

    在编写代码的时候,我对查询这个方法进行了重载,这样调用的时候会根据参数的不同,进而去执行不同的操作,但是......问题来了.想法都是美好的,实际情况却不是我理想的状态.运行代码的时候他动了几下,然后 ...

  9. 南京邮电大学java第一次实验报告

    实 验 报 告 ( 2017 / 2018学年 第2学期) 课程名称 JAVA语言程序设计 实验名称 Java集成开发环境的安装与使用. Java变量.表达式与控制结构 实验时间 2018 年 4 月 ...

  10. JS中的数据类型和转换

    一.JS中的数据类型 js中的数据类型可以分为五种:number .string .boolean. underfine .null. number:数字类型 ,整型浮点型都包括. string:字符 ...