WOJ 124. Football Coach 网络流
Problem 1124 - Football Coach
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.
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.
the league.
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
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 网络流的更多相关文章
- Soj题目分类
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...
- May 04th 2017 Week 18th Thursday
No matter how far you may fly, never forget where you come from. 无论你能飞多远,都别忘了你来自何方. I never forget w ...
- listen 60
Barbie Exposure May Limit Girls' Career Imagination The ubiquitous Barbie doll: she's been everythin ...
- 数据结构与算法分析 - 网络流入门(Network Flow)
转载:网络流基础篇--Edmond-Karp算法 BY纳米黑客 网络流的相关定义: 源点:有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点. 汇点:另一个点也很特殊, ...
- 17111 Football team
时间限制:1000MS 内存限制:65535K 提交次数:0 通过次数:0 题型: 编程题 语言: C++;C Description As every one known, a footbal ...
- light oj 1153 - Internet Bandwidth【网络流无向图】
1153 - Internet Bandwidth PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...
- 数据结构之网络流入门(Network Flow)简单小节
网络流的相关定义: 源点:有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点. 汇点:另一个点也很特殊,只进不出,叫做汇点. 容量和流量:每条有向边上有两个量,容量和流量,从i到j的容量通常用 ...
- 网络流入门—用于最大流的Dinic算法
"网络流博大精深"-sideman语 一个基本的网络流问题 最早知道网络流的内容便是最大流问题,最大流问题很好理解: 解释一定要通俗! 如右图所示,有一个管道系统,节点{1,2,3 ...
- 网络流入门--最大流算法Dicnic 算法
感谢WHD的大力支持 最早知道网络流的内容便是最大流问题,最大流问题很好理解: 解释一定要通俗! 如右图所示,有一个管道系统,节点{1,2,3,4},有向管道{A,B,C,D,E},即有向图一张. ...
随机推荐
- C语言博客作业—指针
一.PTA实验作业 题目1: 求出数组中最大数和次最大数 1. 本题PTA提交列表 2. 设计思路 定义max表示范围数组中的最大数(初值设为a[0]),z表示找到的元素在数组中的位置: 定义指针*b ...
- 每日冲刺报告——Day2(Java-Team)
第二天报告(11.3 周五) 团队:Java-Team 成员: 章辉宇(284) 吴政楠(286) 陈阳(PM:288) 韩华颂(142) 胡志权(143) github地址:https://git ...
- mysql命令行大全
1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...
- vue 内联样式style中的background
在我们使用vue开发的时候 有很多时候我们需要用到背景图 这个时候会直接使用 内联样式 直接把你拿到的数据拼接上去 注意 在vue中直接使用style时 花括号一定别忘记 还有就是你的url一定 ...
- JAVA_SE基础——67.System类
System类对大家都不陌生吧! 以前经常需要打印结果时使用的都是"System.out.println()"语句,这句代码中就使用了System类.System类定义了一些与系统 ...
- 扩展Microsoft Graph数据结构 - 架构扩展
前言 此前我有一篇 文章 讲解了Microsoft Graph的一种数据扩展技术-- 开发扩展(Open Extensions),它可以实现在支持的对象(例如用户,组等)上面附加任意的数据.但开放扩展 ...
- 前端基础之html-Day12
1.web服务本质 import socket def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bi ...
- 开发一个http代理服务器
参考链接: http://www.cnblogs.com/jivi/archive/2013/03/10/2952860.html https://www.2cto.com/kf/201405/297 ...
- Spring中获取request的几种方法,及其线程安全性分析
前言 本文将介绍在Spring MVC开发的web系统中,获取request对象的几种方法,并讨论其线程安全性. 原创不易,如果觉得文章对你有帮助,欢迎点赞.评论.文章有疏漏之处,欢迎批评指正. 欢迎 ...
- Tess4J OCR简单使用教程
Tess4J简介 Tesseract-OCR支持中文识别,并且开源和提供全套的训练工具,是快速低成本开发的首选.而Tess4J则是Tesseract在Java PC上的应用.在英文和数字识别中性能还是 ...