Description

Breaking news! A Russian billionaire has bought a yet undisclosed NBA team. He's planning to invest huge effort and money into making that team the best. And in fact he's been very specific about the expected result: the first place. 
Being his advisor, you need to determine whether it's possible for your team to finish first in its division or not. 
More formally, the NBA regular season is organized as follows: all teams play some games, in each game one team wins and one team loses. Teams are grouped into divisions, some games are between the teams in the same division, and some are between the teams in different divisions. 
Given the current score and the total number of remaining games for each team of your division, and the number of remaining games between each pair of teams in your division, determine if it's possible for your team to score at least as much wins as any other team in your division.

Input

The first line of input contains N (2 ≤ N ≤ 20) — the number of teams in your division. They are numbered from 1 to N, your team has number 1. 
The second line of input contains N integers w1w2,..., wN, where wi is the total number of games that ith team has won to the moment. 
The third line of input contains N integers r1r2,..., rN, where ri is the total number of remaining games for the ith team (including the games inside the division). 
The next N lines contain N integers each. The jth integer in the ith line of those contains aij — the number of games remaining between teams i and j. It is always true that aij=a ji and aii=0, for all iai1ai2 +... + aiN ≤ ri
All the numbers in input are non-negative and don't exceed 10\,000.

Output

On the only line of output, print "

YES

" (without quotes) if it's possible for the team 1 to score at least as much wins as any other team of its division, and "

NO

" (without quotes) otherwise.

题目大意:某小组有n支队伍要比赛,现在每支队伍已经赢了w[i]场,每支队伍还要比r[i]场,每场分同小组竞赛和不同小组竞赛,然后给一个矩阵(小组内竞赛),i行j列为队伍i与队伍j还要比多少场比赛,问队伍1有没有在小组内拿最高分(假设赢一场得一分)的可能性(可以跟其他队伍同分)

思路:首先,队伍1要赢,最好是要1把所有比赛都赢了(包括小组内和小组外),然后其他小组的分都要尽量低,所以其他队伍都要输掉小组外的比赛。那么设小组1能赢max_score场。那么怎么分配其他比赛的获胜方呢?这里就要用到网络流建图。从源点到每支队伍间的比赛连一条边,容量为该竞赛的场数,然后该竞赛再向该比赛的两支队伍连一条容量为无穷大的边(你喜欢容量为场数也可以o(╯□╰)o)。然后,每支队伍(不包括1),连一条容量为max_score - w[i]的边到汇点(不能让这支队伍赢太多啊会超过1的o(╯□╰)o)。如果最大流等于小组内比赛数,那就是YES(分配了所有比赛的结果,还是没人能超过max_score,有可行解),否则输出NO。

 #include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; const int INF = 0x7fff7fff;
const int MAX = ;
const int MAXN = MAX * MAX;
const int MAXE = * MAXN; struct Dinic {
int head[MAXN], cur[MAXN], dis[MAXN];
int to[MAXE], next[MAXE], cap[MAXE], flow[MAXE];
int n, st, ed, ecnt; void init() {
memset(head, , sizeof(head));
ecnt = ;
} void add_edge(int u, int v, int c) {
to[ecnt] = v; cap[ecnt] = c; flow[ecnt] = ; next[ecnt] = head[u]; head[u] = ecnt++;
to[ecnt] = u; cap[ecnt] = ; flow[ecnt] = ; next[ecnt] = head[v]; head[v] = ecnt++;
} bool bfs() {
memset(dis, , sizeof(dis));
queue<int> que; que.push(st);
dis[st] = ;
while(!que.empty()) {
int u = que.front(); que.pop();
for(int p = head[u]; p; p = next[p]) {
int v = to[p];
if(!dis[v] && cap[p] > flow[p]) {
dis[v] = dis[u] + ;
que.push(v);
if(v == ed) return true;
}
}
}
return dis[ed];
} int dfs(int u, int a) {
if(u == ed || a == ) return a;
int outflow = , f;
for(int &p = cur[u]; p; p = next[p]) {
int v = to[p];
if(dis[u] + == dis[v] && (f = dfs(v, min(a, cap[p] - flow[p]))) > ) {
flow[p] += f;
flow[p ^ ] -= f;
outflow += f;
a -= f;
if(a == ) break;
}
}
return outflow;
} int Maxflow(int ss, int tt, int nn) {
st = ss; ed = tt; n = nn;
int ans = ;
while(bfs()) {
for(int i = ; i <= n; ++i) cur[i] = head[i];
ans += dfs(st, INF);
}
return ans;
}
} G; int r[MAX], w[MAX];
int n; int main() {
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", &w[i]);
for(int i = ; i <= n; ++i) scanf("%d", &r[i]);
int max_score = w[] + r[], node_cnt = n, game_cnt = ;
for(int i = ; i <= n; ++i)
if(max_score < w[i]) {puts("NO"); return ;}
G.init();
int ss = ;
for(int i = ; i <= n; ++i) for(int j = ; j <= n; ++j) {
int x; scanf("%d", &x);
if(i == || i >= j || x == ) continue;
game_cnt += x;
G.add_edge(ss, ++node_cnt, x);
G.add_edge(node_cnt, i, INF);
G.add_edge(node_cnt, j, INF);
}
int tt = ++node_cnt;
for(int i = ; i <= n; ++i) G.add_edge(i, tt, max_score - w[i]);
if(G.Maxflow(ss, tt, node_cnt) == game_cnt) puts("YES");
else puts("NO");
}

SGU 326 Perspective(最大流)的更多相关文章

  1. SGU 326 Perspective ★(网络流经典构图の竞赛问题)

    [题意]有n(<=20)只队伍比赛, 队伍i初始得分w[i], 剩余比赛场数r[i](包括与这n只队伍以外的队伍比赛), remain[i][j]表示队伍i与队伍j剩余比赛场数, 没有平局, 问 ...

  2. sgu 326(经典网络流构图)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=13349 题目大意:有N个球队在同一个赛区,已知他们胜利的场数,还剩 ...

  3. [转] POJ图论入门

    最短路问题此类问题类型不多,变形较少 POJ 2449 Remmarguts' Date(中等)http://acm.pku.edu.cn/JudgeOnline/problem?id=2449题意: ...

  4. Soj题目分类

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

  5. 图论常用算法之一 POJ图论题集【转载】

    POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:h ...

  6. 千里积于跬步——流,向量场,和微分方程[转载]

    在很多不同的科学领域里面,对于运动或者变化的描述和建模,都具有非常根本性的地位--我个人认为,在计算机视觉里面,这也是非常重要的. 什么是"流"? 在我接触过的各种数学体系中,对于 ...

  7. SGU 176 【带上下界的有源汇的最小流】

    ---恢复内容开始--- 题意: 给了n个点,m条有向边. 接下来m行,每条边给起点终点与容量,以及一个标记. 标记为1则该边必须满容量,0表示可以在容量范围内任意流. 求: 从源点1号点到终点n号点 ...

  8. 【无源汇上下界最大流】SGU 194 Reactor Cooling

    题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=194 题目大意: n个点(n<20000!!!不是200!!!RE了无数次) ...

  9. SGU 176 Flow construction(有源汇上下界最小流)

    Description 176. Flow construction time limit per test: 1 sec. memory limit per test: 4096 KB input: ...

随机推荐

  1. 日期格式操作,在oracle和mysql中的实现

    oracle add_months(日期格式值 , 整数n)  当整数n=12时,代表一年,向后推迟一年,若n=-12代表回退一年 如 to_char(add_months(to_date('2018 ...

  2. 缓存反向代理-Varnish

    简介 Varnish是一款高性能.开源的缓存反向代理服务器.它从客户端接受请求,并尝试从缓存中响应请求,如果无法从缓存中提供响应,Varnish 向后端服务器发起请求,获取响应,将响应存储在缓存中,然 ...

  3. js滚动监听

    下边代码,是监听滚动条只要移动,下方的返回顶部的div显示与隐藏的代码 ? 1 2 3 4 5 6 7 8 window.onscroll = function () {  var t = docum ...

  4. Canvas状态的保存与恢复

    Canvas的API提供了save()和restore()的方法,用于保存及恢复当前canvas绘图环境的所有属性. save()与restore()方法可以嵌套调用 save()方法将当前绘图环境压 ...

  5. php 计算两个文件的相对路径

    <?php /** * 计算两个文件的相对路径 */ function relative_path($path1, $path2) { $arr1 = explode('/', dirname( ...

  6. linux 操作系统之磁盘管理

    磁盘管理 存储设备:硬盘 , U盘 , 移动硬盘 , 光盘 , 软件. 组装一台电脑 无法被修改 df -h #查看磁盘分区的情况 , 可用的. 查看磁盘或者目录的内容 df “df” 常用的 “-i ...

  7. QWebView 与Js 交互

    我本愚钝,在网上搜了一下没找到可以运行的栗子,遂在这记录一下吧. 环境:win10 64位系统  qt 4.8.7 (mingw32) qtcreator(4.5.0) 1. 建立一个 Widgets ...

  8. DQL数据查询

    set hive.fetch.task.conversion=more; -- 避免触发MR job select distinct name from employee_id limit 2; -- ...

  9. Python中的封装,继承和多态

    面向对象的三大特性:封装,继承和多态 封装:在类的内部定义属性和方法,通过对象或类名来访问属性和方法,隐藏功能的实现细节,也可以设置访问权限. 广义的封装:实例化一个对象,给对象空间封装一些属性:狭义 ...

  10. AS 3.1 多library合并打包成aar的正确方式(fat-aar)

    前言 主要参考fat-aar来合并打包. 但是这个fat-aar很久没维护了,如果直接使用它会有很多问题.由于对gradle脚本也不是太熟,就只能顺着它的意思,将gradle降级成2.2.3的版本. ...