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. excel批量转换为CSV格式,xls批量导出csv格式

    工具/原料   excel 2013 地址链接:http://pan.baidu.com/s/1c1ZABlu 密码:d3rc 方法/步骤     首选我们把需要导出为CVS的Excel文件整理集中到 ...

  2. ACM 2000~2002

    ACM  2000  输入三个字符后,按各个字符的ASCⅡ码从小打到的顺序输出这三个字符. import java.util.Scanner; public class Lengxc {public ...

  3. tornado用户指引(三)------tornado协程使用和原理(二)

    Python3.5  async和await async和await是python3.5引入的2个新的关键字(用这两个关键字编写的函数也称之为"原生协程"). 从tornado4. ...

  4. H5混合开发进阶之inspect调试

    h5界面嵌套在原生app内部的时候,需要调用原生的方法,传递数据.中间难以调试代码,. 用google的 inspect调试.查看数据的传输方式. 1.adb连接正常,打开手机USB调试 2.第一次使 ...

  5. Spring Security学习笔记(一)

    认证和权限控制 AuthenticationManager是认证的主要接口,它只有一个authenticate方法,可以做3件事情. 返回一个认证信息(Authentication),表示认证成功 抛 ...

  6. collections.Counter类统计列表元素出现次数

    # 使用collections.Counter类统计列表元素出现次数 from collections import Counter names = ["Stanley", &qu ...

  7. thinkphp 5.1/tp5.1 route路由bug

    tp5.1下面RuleItem类中,match方法. 如果同一个控制器下面,写了两个路由,后一个路由比包含前一个路由,则访问后一个路由地址的时候,会跳转到前面定义的那个路由

  8. ie 8在打印网页的时候打印预览是空白的

    win 7专业版系统中的ie 8在打印网页的时候打印预览是空白的,打印出来也是空白的,但是用别的浏览器打印没有问题 根据您的描述,该问题主要是由于保护模式下%Temp%\Low不正常工作引起的. 建议 ...

  9. linux常用的命令之一chmod

    用权限 : 所有使用者 使用方式 : chmod [-cfvR] [--help] [--version] mode file... u 表示该档案的拥有者,g 表示与该档案的拥有者属于同一个群体(g ...

  10. python爬取视频网站m3u8视频,下载.ts后缀文件,合并成整视频

    最近发现一些网站,可以解析各大视频网站的vip.仔细想了想,这也算是爬虫呀,爬的是视频数据. 首先选取一个视频网站,我选的是 影视大全 ,然后选择上映不久的电影 “一出好戏” . 分析页面 我用的是c ...