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. ifream爱恨情缘

    开幕场景 iframe.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...

  2. Ubuntu下erlang连接SQL SERVER 2008

    erlang连接SQL Server使用ODBC方法,但在网络上还是缺少资料,自己折腾了2天才成功.现在特记录下来,以供大家借鉴. 基本思路是 erlang odbcserver + unixodbc ...

  3. asp.net中Repeater结合js实现checkbox的全选/全不选

    前台界面代码: <input name="CheckAll" type="checkbox" id="CheckAll" value= ...

  4. oracle 11g ADG实施手册(亲测,已成功部署多次)

    一:实验环境介绍 虚拟机系统:    RHEL Linux 6.4(64位) 数据库版本:    Oracle 11gR2 11.2.0.4 (64位) IP地址规划: 主数据库 192.168.11 ...

  5. 浅述Try {} Catch{} 作用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test ...

  6. MYsql 数据库密码忘记(Window)-2(mysql 5.7)

    很久没用Mysql了,再次打开,发现用不了了,密码忘了,服务也无法打开,在cmd中输入mysql之后,显示不是内部指令. 看来问题是mysql服务打不开了 (1)在cmd中 输入net start m ...

  7. touchSwipe 上下左右滑动,二指缩放 效果不好。

    $(function(){ var _showImgW; var _showImgH; var _showImgMT; var _showImgML; $("#imgDiv").s ...

  8. jira & analytics

    jira & analytics jira 代码有毒呀 http://jira.xgqfrms.xyz:8888/rest/analytics/1.0/publish/bulk { resou ...

  9. [NOIP2016] 天天爱跑步 桶 + DFS

    ---题面--- 题解: 很久以前就想写了,一直没敢做,,,不过今天写完没怎么调就过了还是很开心的. 首先我们观察到跑步的人数是很多的,要一条一条的遍历显然是无法承受的,因此我们要考虑更加优美的方法. ...

  10. 简单谈谈Docker镜像的使用方法_docker

    在上篇文章(在Docker中搭建Nginx服务器)中,我们已经介绍了如何快速地搭建一个实用的Nginx服务器.这次我们将围绕Docker镜像(Docker Image),介绍其使用方法.包括三部分: ...