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. ubuntu18.04安装搜狗输入法

    首先,安装Fcitx输入框架 sudo apt install fcitx 其次,上搜狗输入法官网下载Linux版本搜狗输入法(32位和64位根据自己情况,在虚拟机上用浏览器下载即可 然后进入相应的下 ...

  2. Spring Boot 微信-验证服务器有效性【转】

    转:https://blog.csdn.net/jeikerxiao/article/details/68064145 概述 接入微信公众平台开发,开发者需要按照如下步骤完成: 在自己服务器上,开发验 ...

  3. Java中BigDecimal的一个除法异常

    java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal res ...

  4. IO流,Properties基本功能和遍历

    import java.util.Enumeration; import java.util.Iterator; import java.util.Properties; import java.ut ...

  5. HTML+jq简单轮播图

    .main{    width: 100%;    min-width: 1100px;    display: table;    margin: 0 auto;    text-align: ce ...

  6. 关于NPOI导出excel文件(xls和xlsx两种格式)提示格式不符的问题

    这两天在做导出excel文件的时候遇到这个问题 本来我导出的格式是xlsx格式的,但是下载得到的文件格式变成了xls, 一开始以为是返回的contenttype设置错了 return File(ms, ...

  7. .net第三方数据库物理卡号同步功能实现

    本地数据库用的是Oracle,第三方数据库是SQL Server,连接字符串保存在web.config里面. 第三方数据库为增量,每次读取要记录读取的最大位置.我是保存在本地txt文件里面. //保存 ...

  8. Zookeeper -- 关于Zookeeper

    Zookeeper是什么? 分布式协调框架 Zookeeper中文件呈树形结构,树形结构下包含多个节点,称为Znode:zk中节点存储数据不超过1M,指得是Znode中存储数据不超过1M Zookee ...

  9. Vue 从零开始--搭建环境

    简要:继项目空闲后,开始着手vue的学习;为此向大家分享其中的艰辛和搭建办法,希望能够跟各位VUE大神学习探索,如果有不对或者好的建议告知下:*~*! 一.什么是VUE? 是一种node.js框架,特 ...

  10. Scala学习笔记(四)—— 数组

    定长数组Array 定义定长数组用Array,有如下几种方法: 初始化一个长度为8的定长数组,其所有元素默认值均为0 scala> new Array[Int](8) res0: Array[I ...