Time Limit: 2 Seconds      Memory Limit: 32768 KB      Special Judge


Gensokyo is a world which exists quietly beside ours, separated by a mystical border. It is a utopia where humans and other beings such as fairies, youkai(phantoms), and gods live peacefully together. Shameimaru Aya is a crow tengu with the ability to manipulate wind who has been in Gensokyo for over 1000 years. She runs the Bunbunmaru News - a newspaper chock-full of rumors, and owns the Bunkachou - her record of interesting observations for Bunbunmaru News articles and pictures of beautiful danmaku(barrange) or cute girls living in Gensokyo. She is the biggest connoisseur of rumors about the girls of Gensokyo among the tengu. Her intelligence gathering abilities are the best in Gensokyo!

During the coming n days, Aya is planning to take many photos of m cute girls living in Gensokyo to write Bunbunmaru News daily and record at least Gx photos of girl x in total in the Bunkachou. At the k-th day, there are Ck targets, Tk1, Tk2, ..., TkCk. The number of photos of target Tki that Aya takes should be in range [Lki, Rki], if less, Aya cannot write an interesting article, if more, the girl will become angry and use her last spell card to attack Aya. What's more, Aya cannot take more than Dk photos at the k-th day. Under these constraints, the more photos, the better.

Aya is not good at solving this complex problem. So she comes to you, an earthling, for help.

Input

There are about 40 cases. Process to the end of file.

Each case begins with two integers 1 <= n <= 365, 1 <= m <= 1000. Then m integers, G1, G2, ..., Gm in range [0, 10000]. Then n days. Each day begins with two integer 1 <= C <= 100, 0 <= D <= 30000. Then C different targets. Each target is described by three integers, 0 <= T < m, 0 <= L <= R <= 100.

Output

For each case, first output the number of photos Aya can take, -1 if it's impossible to satisfy her needing. If there is a best strategy, output the number of photos of each girl Aya should take at each day on separate lines. The output must be in the same order as the input. If there are more than one best strategy, any one will be OK.

Output a blank line after each case.

Sample Input

2 3
12 12 12
3 18
0 3 9
1 3 9
2 3 9
3 18
0 3 9
1 3 9
2 3 9 2 3
12 12 12
3 18
0 3 9
1 3 9
2 3 9
3 18
0 0 3
1 3 6
2 6 9 2 3
12 12 12
3 15
0 3 9
1 3 9
2 3 9
3 21
0 0 3
1 3 6
2 6 12

Sample Output

36
6
6
6
6
6
6 36
9
6
3
3
6
9 -1

图论 网络流

复习了一波有上下界网络流的姿势。

顺便复习了一下东方的设定

题面里的罗马音居然都能看懂,是该说新标日姿势没忘光呢还是四斋蒸鹅心呢

如何求带上下界的最大流?

在求出可行流以后,删掉超级源汇,从旧源到旧汇跑网络流,把能用的残余流量都流掉,再加上原先的下界即可。

好像这道题的SPJ挂掉了,近几个月的提交结果全是Judge Internal Error

代码不保证正确,仅供参考

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct edge{
int v,nxt,f;
}e[mxn<<];
int hd[mxn],mct=;
inline void add_edge(int u,int v,int f){
e[++mct].v=v;e[mct].nxt=hd[u];e[mct].f=f;hd[u]=mct;return;
}
inline void insert(int u,int v,int f){
// printf("ins:%d %d %d\n",u,v,f);
add_edge(u,v,f);add_edge(v,u,);
}
int ST,ED,S,T;
int n,m;
queue<int>q;
int d[mxn];
bool BFS(){
for(int i=;i<=ED;i++)d[i]=;
q.push(ST);
d[ST]=;
while(!q.empty()){
int u=q.front();q.pop();
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(e[i].f && !d[v]){
d[v]=d[u]+;
q.push(v);
}
}
}
return d[ED];
}
int cur[mxn];
int DFS(int u,int lim){
if(u==ED)return lim;
int f=,tmp;
for(int &i=cur[u];i;i=e[i].nxt){
int v=e[i].v;
if(e[i].f && d[v]==d[u]+ && (tmp=DFS(v,min(lim,e[i].f)))){
e[i].f-=tmp;
e[i^].f+=tmp;
lim-=tmp;
f+=tmp;
if(!lim)return f;
}
}
d[u]=;
return f;
}
int Dinic(){
int res=,flow=;
while(BFS()){
for(int i=;i<=ED;i++)cur[i]=hd[i];
while(flow=DFS(ST,INF))res+=flow;
}
return res;
}
//
int du[mxn];
int D[mxn];
int down[][];
bool vis[][];
int id[][];
void solve_MX(){
int i,j;
ST=S;ED=T;
int ans=Dinic();
for(i=;i<=n;i++){
for(j=hd[i];j;j=e[j].nxt){
int v=e[j].v;
if(v>n && v<T){
down[i][v-n]+=e[j^].f;
}
}
}
printf("%d\n",ans);
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(vis[i][j])
printf("%d\n",down[i][j]);
}
}
return;
}
void init(){
memset(hd,,sizeof hd);mct=;
memset(vis,,sizeof vis);
memset(du,,sizeof du);
return;
}
int main(){
freopen("in.txt","r",stdin);
int i,j;
while(scanf("%d%d",&n,&m)!=EOF){
init();
S=;T=n+m+;ST=T+;ED=ST+;
int u,v,w,L,R;
for(i=;i<=m;i++){
w=read();
du[i+n]-=w;
du[T]+=w;
insert(i+n,T,INF-w);
}
for(i=;i<=n;i++){
int C=read();D[i]=read();
insert(S,i,D[i]);
for(j=;j<=C;j++){
v=read()+;L=read();R=read();
du[i]-=L;
du[v+n]+=L;
down[i][v]=L;
vis[i][v]=;
insert(i,v+n,R-L);
id[i][v]=mct;
}
}
insert(T,S,INF);
int smm=;
for(i=S;i<=T;i++){
if(du[i]>)smm+=du[i],insert(ST,i,du[i]);
else insert(i,ED,-du[i]);
}
int res=Dinic();//printf("res:%d smm:%d\n",res,smm);
if(res!=smm){
puts("-1");continue;
}
else{
solve_MX();
}
}
return ;
}

ZOJ3229 Shoot the Bullet [未AC]的更多相关文章

  1. ZOJ3229 Shoot the Bullet(有源汇流量有上下界网络的最大流)

    题目大概说在n天里给m个女孩拍照,每个女孩至少要拍Gi张照片,每一天最多拍Dk张相片且都有Ck个拍照目标,每一个目标拍照的张数要在[Lki, Rki]范围内,问最多能拍几张照片. 源点-天-女孩-汇点 ...

  2. ZOJ3229 Shoot the Bullet(有源汇的上下界最大流)

    #pragma warning(disable:4996) #include <iostream> #include <cstring> #include <string ...

  3. zoj3229 Shoot the Bullet(有源汇有上下界的最大流)

    题意: 一个屌丝给m个女神拍照,计划拍照n天,每一天屌丝给给定的C个女神拍照,每天拍照数不能超过D张,而且给每个女神i拍照有数量限制[Li,Ri],对于每个女神n天的拍照总和不能少于Gi,如果有解求屌 ...

  4. ZOJ3229 Shoot the Bullet

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20756 思路:就讲一下有源汇上下界最大流的做法吧!对于所有的边,就按照无源汇 ...

  5. zoj3229 Shoot the Bullet (有源汇最大流)

    题目大意:文文要给幻想乡的女♂孩子们拍照,一共n天,m个女♂孩子,每天文文至多拍D[i]张照片,每个女♂孩子总共要被文文至少拍G[i]次.在第i天,文文可以拍c[i]个女♂孩子,c[i]个女♂孩子中每 ...

  6. zoj 3229 Shoot the Bullet(无源汇上下界最大流)

    题目:Shoot the Bullet 收藏:http://www.tuicool.com/articles/QRr2Qb 把每一天看成一个点,每个女孩也看成一个点,增加源和汇s.t,源向每一天连上[ ...

  7. 九度OJ 1016 火星A + B 未AC版,整型存储不下

    #include <iostream> #include <string.h> #include <sstream> #include <math.h> ...

  8. ZOJ 3229 Shoot the Bullet [上下界最大流]

    ZOJ 3229 Shoot the Bullet 题意:此生无悔入东方 上下界最大流 spj挂掉了我也不知道对不对,把代码放这里吧以后正常了可能会评测一下 #include <iostream ...

  9. Shoot the Bullet ZOJ - 3229 有源汇有上下界的最大流

    /** zoj提交评判不了,所以不知道代码正不正确.思路是应该没问题的.如果有不对的地方,请多指教. 题目:Shoot the Bullet ZOJ - 3229 链接:https://vjudge. ...

随机推荐

  1. 对Android体系结构的理解--后续会补充

    1.最底层_硬件 任何Android设备最底层的硬件包括 显示屏, wifi ,存储设备 等. Android最底层的硬件会根据需要进行裁剪,选择自己需要的硬件. 2.Linux内核层 该层主要对硬件 ...

  2. 《学习OpenCV》课后习题解答1

    题目:(P104) 下面这个练习是帮助掌握矩阵类型.创造一个三通道二维矩阵,字节类型,大小为100*100,并设置所有数值为0. a.在矩阵中使用cvCircle( CvArr* img, CvPoi ...

  3. 修改IntelliJ IDEA代码头注释

  4. Linux服务器记录并查询历史操作记录

    Linux服务器在使用过程中,经常会有除自己之外的其他人员使用.并不是每个人都对Linux服务器特别熟悉,难免会有一些操作导致服务器报错. 因此,监控Linux服务器的操作并记录下来,是非常有必要的! ...

  5. 【bzoj1858】[Scoi2010]序列操作 线段树区间合并

    题目描述 lxhgww最近收到了一个01序列,序列里面包含了n个数,这些数要么是0,要么是1,现在对于这个序列有五种变换操作和询问操作: 0 a b 把[a, b]区间内的所有数全变成0 1 a b ...

  6. CSS定义input disabled样式

    disabled 属性规定应该禁用 input 元素.被禁用的 input 元素既不可用,也不可点击.可以设置 disabled 属性,直到满足某些其他的条件为止(比如选择了一个复选框等等).然后,就 ...

  7. img 和 background-image 优劣比较

    一. 简单来说,img是内容部分的东西,css的background-image是修饰性的东西. img------从页面元素来说,如果是页面中的图片是作为内容出现的,比如广告图片,比如产品图片,那么 ...

  8. 从APNIC提取IP信息

    从APNIC提取IP信息 https://blog.csdn.net/nullzeng/article/details/17538009 Apnic介绍简而言之,Apnic是全球5个地区级的Inter ...

  9. BZOJ5011 & 洛谷4065 & LOJ2275:[JXOI2017]颜色——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5011 https://www.luogu.org/problemnew/show/P4065 ht ...

  10. BZOJ1030:[JSOI2007]文本生成器——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1030 Description JSOI交给队员ZYX一个任务,编制一个称之为“文本生成器”的电脑软件 ...